forked from 0x2620/pandora
Allow 'query' to be omitted from find*() (fixes #2883)
I hit this in findDocuments() so thought I'd fix them all.
This commit is contained in:
parent
b121b58a86
commit
47d8d67c3d
7 changed files with 22 additions and 12 deletions
|
@ -116,8 +116,9 @@ class DocumentManager(Manager):
|
||||||
|
|
||||||
#join query with operator
|
#join query with operator
|
||||||
qs = self.get_query_set()
|
qs = self.get_query_set()
|
||||||
conditions = parseConditions(data['query'].get('conditions', []),
|
query = data.get('query', {})
|
||||||
data['query'].get('operator', '&'),
|
conditions = parseConditions(query.get('conditions', []),
|
||||||
|
query.get('operator', '&'),
|
||||||
user, item)
|
user, item)
|
||||||
if conditions:
|
if conditions:
|
||||||
qs = qs.filter(conditions)
|
qs = qs.filter(conditions)
|
||||||
|
|
|
@ -148,7 +148,7 @@ def _order_query(qs, sort, item=None):
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
def get_item(query):
|
def get_item(query):
|
||||||
for c in query.get('conditions'):
|
for c in query.get('conditions', []):
|
||||||
if c.get('key') == 'item':
|
if c.get('key') == 'item':
|
||||||
return c.get('value')
|
return c.get('value')
|
||||||
return None
|
return None
|
||||||
|
@ -161,7 +161,7 @@ def parse_query(data, user):
|
||||||
if key in data:
|
if key in data:
|
||||||
query[key] = data[key]
|
query[key] = data[key]
|
||||||
query['qs'] = models.Document.objects.find(data, user).exclude(name='')
|
query['qs'] = models.Document.objects.find(data, user).exclude(name='')
|
||||||
query['item'] = get_item(data['query'])
|
query['item'] = get_item(data.get('query', {}))
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,9 @@ class EntityManager(Manager):
|
||||||
def find(self, data, user, item=None):
|
def find(self, data, user, item=None):
|
||||||
#join query with operator
|
#join query with operator
|
||||||
qs = self.get_query_set()
|
qs = self.get_query_set()
|
||||||
conditions = parseConditions(data['query'].get('conditions', []),
|
query = data.get('query', {})
|
||||||
data['query'].get('operator', '&'),
|
conditions = parseConditions(query.get('conditions', []),
|
||||||
|
query.get('operator', '&'),
|
||||||
user, item)
|
user, item)
|
||||||
if conditions:
|
if conditions:
|
||||||
qs = qs.filter(conditions)
|
qs = qs.filter(conditions)
|
||||||
|
|
|
@ -120,8 +120,9 @@ class ListManager(Manager):
|
||||||
|
|
||||||
#join query with operator
|
#join query with operator
|
||||||
qs = self.get_query_set()
|
qs = self.get_query_set()
|
||||||
conditions = parseConditions(data['query'].get('conditions', []),
|
query = data.get('query', {})
|
||||||
data['query'].get('operator', '&'),
|
conditions = parseConditions(query.get('conditions', []),
|
||||||
|
query.get('operator', '&'),
|
||||||
user)
|
user)
|
||||||
if conditions:
|
if conditions:
|
||||||
qs = qs.filter(conditions)
|
qs = qs.filter(conditions)
|
||||||
|
|
|
@ -80,7 +80,10 @@ def findLists(request, data):
|
||||||
return x['key'] == 'status' and \
|
return x['key'] == 'status' and \
|
||||||
x['value'] == 'featured' and \
|
x['value'] == 'featured' and \
|
||||||
x['operator'] in ('=', '==')
|
x['operator'] in ('=', '==')
|
||||||
is_featured = len(filter(is_featured_condition, data['query'].get('conditions', []))) > 0
|
is_featured = any(
|
||||||
|
is_featured_condition(x)
|
||||||
|
for x in data.get('query', {}).get('conditions', [])
|
||||||
|
)
|
||||||
|
|
||||||
if is_section_request:
|
if is_section_request:
|
||||||
qs = query['qs']
|
qs = query['qs']
|
||||||
|
|
|
@ -119,8 +119,9 @@ class TextManager(Manager):
|
||||||
|
|
||||||
#join query with operator
|
#join query with operator
|
||||||
qs = self.get_query_set()
|
qs = self.get_query_set()
|
||||||
conditions = parseConditions(data['query'].get('conditions', []),
|
query = data.get('query', {})
|
||||||
data['query'].get('operator', '&'),
|
conditions = parseConditions(query.get('conditions', []),
|
||||||
|
query.get('operator', '&'),
|
||||||
user)
|
user)
|
||||||
if conditions:
|
if conditions:
|
||||||
qs = qs.filter(conditions)
|
qs = qs.filter(conditions)
|
||||||
|
|
|
@ -212,7 +212,10 @@ def findTexts(request, data):
|
||||||
return x['key'] == 'status' and \
|
return x['key'] == 'status' and \
|
||||||
x['value'] == 'featured' and \
|
x['value'] == 'featured' and \
|
||||||
x['operator'] in ('=', '==')
|
x['operator'] in ('=', '==')
|
||||||
is_featured = len(filter(is_featured_condition, data['query'].get('conditions', []))) > 0
|
is_featured = any(
|
||||||
|
is_featured_condition(x)
|
||||||
|
for x in data.get('query', {}).get('conditions', [])
|
||||||
|
)
|
||||||
|
|
||||||
if is_section_request:
|
if is_section_request:
|
||||||
qs = query['qs']
|
qs = query['qs']
|
||||||
|
|
Loading…
Reference in a new issue