From ce9d20c339e370affd7738510d147de5ca66bdfa Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 22 Apr 2018 14:22:42 +0200 Subject: Refactoring of query owns (refs #4060) --- ishtar_common/models.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 2ebe07961..c14635a51 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -364,6 +364,34 @@ class OwnPerms(object): items = [(i, cls.get_short_menu_class(i.pk)) for i in items] return items + @classmethod + def _get_query_owns_dicts(cls, ishtaruser): + """ + List of query own dict to construct the query. + Each dict are join with an AND operator, each dict key, values are + joined with OR operator + """ + return [] + + @classmethod + def _construct_query_own(cls, prefix, dct_list): + q = None + for subquery_dict in dct_list: + subquery = None + for k in subquery_dict: + subsubquery = Q(**{prefix + k: subquery_dict[k]}) + if subquery: + subquery |= subsubquery + else: + subquery = subsubquery + if not subquery: + continue + if q: + q &= subquery + else: + q = subquery + return q + class Cached(object): slug_field = 'txt_idx' -- cgit v1.2.3