From 47d8d67c3dfd48249d8f0e57a08eb042b05a58d7 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Mon, 15 Feb 2016 14:21:36 +0000 Subject: [PATCH] Allow 'query' to be omitted from find*() (fixes #2883) I hit this in findDocuments() so thought I'd fix them all. --- pandora/document/managers.py | 5 +++-- pandora/document/views.py | 4 ++-- pandora/entity/managers.py | 5 +++-- pandora/itemlist/managers.py | 5 +++-- pandora/itemlist/views.py | 5 ++++- pandora/text/managers.py | 5 +++-- pandora/text/views.py | 5 ++++- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pandora/document/managers.py b/pandora/document/managers.py index 714da7e..2ea5079 100644 --- a/pandora/document/managers.py +++ b/pandora/document/managers.py @@ -116,8 +116,9 @@ class DocumentManager(Manager): #join query with operator qs = self.get_query_set() - conditions = parseConditions(data['query'].get('conditions', []), - data['query'].get('operator', '&'), + query = data.get('query', {}) + conditions = parseConditions(query.get('conditions', []), + query.get('operator', '&'), user, item) if conditions: qs = qs.filter(conditions) diff --git a/pandora/document/views.py b/pandora/document/views.py index c2af5b4..c2c3612 100644 --- a/pandora/document/views.py +++ b/pandora/document/views.py @@ -148,7 +148,7 @@ def _order_query(qs, sort, item=None): return qs def get_item(query): - for c in query.get('conditions'): + for c in query.get('conditions', []): if c.get('key') == 'item': return c.get('value') return None @@ -161,7 +161,7 @@ def parse_query(data, user): if key in data: query[key] = data[key] 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 diff --git a/pandora/entity/managers.py b/pandora/entity/managers.py index 718235a..f1518e5 100644 --- a/pandora/entity/managers.py +++ b/pandora/entity/managers.py @@ -112,8 +112,9 @@ class EntityManager(Manager): def find(self, data, user, item=None): #join query with operator qs = self.get_query_set() - conditions = parseConditions(data['query'].get('conditions', []), - data['query'].get('operator', '&'), + query = data.get('query', {}) + conditions = parseConditions(query.get('conditions', []), + query.get('operator', '&'), user, item) if conditions: qs = qs.filter(conditions) diff --git a/pandora/itemlist/managers.py b/pandora/itemlist/managers.py index 2f69dc0..eef5d6d 100644 --- a/pandora/itemlist/managers.py +++ b/pandora/itemlist/managers.py @@ -120,8 +120,9 @@ class ListManager(Manager): #join query with operator qs = self.get_query_set() - conditions = parseConditions(data['query'].get('conditions', []), - data['query'].get('operator', '&'), + query = data.get('query', {}) + conditions = parseConditions(query.get('conditions', []), + query.get('operator', '&'), user) if conditions: qs = qs.filter(conditions) diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index 243208d..ad742f6 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -80,7 +80,10 @@ def findLists(request, data): return x['key'] == 'status' and \ x['value'] == 'featured' and \ 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: qs = query['qs'] diff --git a/pandora/text/managers.py b/pandora/text/managers.py index 6598d55..de117a6 100644 --- a/pandora/text/managers.py +++ b/pandora/text/managers.py @@ -119,8 +119,9 @@ class TextManager(Manager): #join query with operator qs = self.get_query_set() - conditions = parseConditions(data['query'].get('conditions', []), - data['query'].get('operator', '&'), + query = data.get('query', {}) + conditions = parseConditions(query.get('conditions', []), + query.get('operator', '&'), user) if conditions: qs = qs.filter(conditions) diff --git a/pandora/text/views.py b/pandora/text/views.py index 7e3a1dc..0855d07 100644 --- a/pandora/text/views.py +++ b/pandora/text/views.py @@ -212,7 +212,10 @@ def findTexts(request, data): return x['key'] == 'status' and \ x['value'] == 'featured' and \ 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: qs = query['qs'] -- 2.5.0