summaryrefslogtreecommitdiff
path: root/ishtar_common/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/views.py')
-rw-r--r--ishtar_common/views.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 1f2bc7f67..50acd5595 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -378,6 +378,13 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
old = 'old' in request_items and int(request_items['old'])
except ValueError:
return HttpResponse('[]', mimetype='text/plain')
+
+ relation_types = set()
+ for k in request_items:
+ if k.startswith('relation_types_'):
+ relation_types.add(request_items[k])
+ continue
+
for k in request_keys:
val = request_items.get(k)
if not val:
@@ -460,15 +467,41 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
and_reqs.append(reqs)
break
query = Q(**dct)
- if own:
- query = query & model.get_query_owns(request.user)
for k, or_req in or_reqs:
alt_dct = dct.copy()
alt_dct.pop(k)
alt_dct.update(or_req)
query = query | Q(**alt_dct)
+
+ if relation_types:
+ alt_dct = {
+ 'right_relations__relation_type__pk__in': list(relation_types)}
+ for k in dct:
+ val = dct[k]
+ if k == 'year':
+ k = 'year__exact'
+ alt_dct['right_relations__right_record__' + k] = val
+ if not dct:
+ # fake condition to trick Django (1.4): without it only the
+ # alt_dct is managed
+ query = query & Q(pk__isnull=False)
+ query = query | Q(**alt_dct)
+ for k, or_req in or_reqs:
+ altor_dct = alt_dct.copy()
+ altor_dct.pop(k)
+ for j in or_req:
+ val = or_req[j]
+ if j == 'year':
+ j = 'year__exact'
+ altor_dct['right_relations__right_record__' + j] = val
+ query = query | Q(**altor_dct)
+
+ if own:
+ query = query & model.get_query_owns(request.user)
+
for and_req in and_reqs:
query = query & and_req
+
items = model.objects.filter(query).distinct()
q = request_items.get('sidx')