jsondatastore: also filter on name id when it's the empty string (#27510)
This commit is contained in:
parent
2150c44578
commit
df3f3c12ea
|
@ -64,7 +64,7 @@ class JsonDataStore(BaseResource):
|
|||
description=_('Listing'))
|
||||
def list(self, request, name_id=None, **kwargs):
|
||||
objects = JsonData.objects.filter(datastore=self)
|
||||
if name_id:
|
||||
if name_id is not None:
|
||||
objects = objects.filter(name_id=name_id)
|
||||
return {'data': [{'id': x.uuid, 'text': x.text, 'content': x.content} for x in objects]}
|
||||
|
||||
|
@ -77,7 +77,7 @@ class JsonDataStore(BaseResource):
|
|||
'content': json.loads(request.body),
|
||||
'datastore': self,
|
||||
}
|
||||
if name_id:
|
||||
if name_id is not None:
|
||||
attrs['name_id'] = name_id
|
||||
data = JsonData(**attrs)
|
||||
data.save()
|
||||
|
@ -131,7 +131,7 @@ class JsonDataStore(BaseResource):
|
|||
)
|
||||
def get_by_attribute(self, request, attribute, value, name_id=None):
|
||||
objects = JsonData.objects.filter(datastore=self)
|
||||
if name_id:
|
||||
if name_id is not None:
|
||||
objects = objects.filter(name_id=name_id)
|
||||
for data in objects:
|
||||
if data.content and data.content.get(attribute) == value:
|
||||
|
|
|
@ -81,6 +81,8 @@ def test_jsondatastore_name_id(app, jsondatastore):
|
|||
assert len(resp.json['data']) == 1
|
||||
resp = app.get('/jsondatastore/foobar/data/?name_id=yyy')
|
||||
assert len(resp.json['data']) == 0
|
||||
resp = app.get('/jsondatastore/foobar/data/?name_id=')
|
||||
assert len(resp.json['data']) == 0
|
||||
|
||||
resp = app.post_json('/jsondatastore/foobar/data/create?name_id=yyy', params={'foo': 'bar'})
|
||||
uuid = resp.json['id']
|
||||
|
|
Loading…
Reference in New Issue