diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-01-27 19:24:00 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-01-27 19:24:00 +0100 | 
| commit | 89d6383db0b22fc8a274ef9b7395c2ee1bcb0a1a (patch) | |
| tree | 8bf97c52e86a824093db25131ea12243e96ecd3b /ishtar_common/views.py | |
| parent | 4d3e1d822c1d9eddaa63d2a830f81d2beea50fd3 (diff) | |
| download | Ishtar-89d6383db0b22fc8a274ef9b7395c2ee1bcb0a1a.tar.bz2 Ishtar-89d6383db0b22fc8a274ef9b7395c2ee1bcb0a1a.zip | |
Manage relation types in searches - relation type search for operations
Diffstat (limited to 'ishtar_common/views.py')
| -rw-r--r-- | ishtar_common/views.py | 37 | 
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') | 
