diff options
Diffstat (limited to 'ishtar_common/views_item.py')
| -rw-r--r-- | ishtar_common/views_item.py | 81 | 
1 files changed, 42 insertions, 39 deletions
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 0b36b9bc1..746d359c1 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -483,7 +483,7 @@ def _manage_dated_fields(dated_fields, dct):              if not dct[k]:                  dct.pop(k)              try: -                items = dct[k].split('/') +                items = dct[k].replace('"', '').split('/')                  assert len(items) == 3                  dct[k] = datetime.date(*map(lambda x: int(x),                                              reversed(items))) \ @@ -623,30 +623,33 @@ def _manage_clean_search_field(dct):  def _manage_relation_types(relation_types, dct, query, or_reqs):      for rtype_prefix in relation_types: -        vals = list(relation_types[rtype_prefix]) +        vals = relation_types[rtype_prefix]          if not vals:              continue -        alt_dct = { -            rtype_prefix + 'right_relations__relation_type__pk__in': vals} -        for k in dct: -            val = dct[k] -            if rtype_prefix: -                # only get conditions related to the object -                if rtype_prefix not in k: -                    continue -                # tricky: reconstruct the key to make sense - remove the -                # prefix from the key -                k = k[0:k.index(rtype_prefix)] + \ -                    k[k.index(rtype_prefix) + len(rtype_prefix):] -            if k.endswith('year'): -                k += '__exact' -            alt_dct[rtype_prefix + '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 &= Q(pk__isnull=False) -        query |= Q(**alt_dct) +        vals = list(vals)[0].split(';') +        for v in vals: +            alt_dct = { +                rtype_prefix + 'right_relations__relation_type__label__iexact': +                    v.replace('"', '')} +            for k in dct: +                val = dct[k] +                if rtype_prefix: +                    # only get conditions related to the object +                    if rtype_prefix not in k: +                        continue +                    # tricky: reconstruct the key to make sense - remove the +                    # prefix from the key +                    k = k[0:k.index(rtype_prefix)] + \ +                        k[k.index(rtype_prefix) + len(rtype_prefix):] +                if k.endswith('year'): +                    k += '__exact' +                alt_dct[rtype_prefix + '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 &= Q(pk__isnull=False) +            query |= Q(**alt_dct)          for k, or_req in or_reqs:              altor_dct = alt_dct.copy()              altor_dct.pop(k) @@ -661,7 +664,7 @@ def _manage_relation_types(relation_types, dct, query, or_reqs):      return query -def _contruct_query(relation_types, dct, or_reqs, and_reqs): +def _construct_query(relation_types, dct, or_reqs, and_reqs):      # manage multi value not already managed      for key in dct.keys(): @@ -869,18 +872,6 @@ def get_item(model, func_name, default_name, extra_request_keys=[],          except ValueError:              return HttpResponse('[]', content_type='text/plain') -        # manage relations types -        if 'relation_types' not in my_relation_types_prefix: -            my_relation_types_prefix['relation_types'] = '' -        relation_types = {} -        for rtype_key in my_relation_types_prefix: -            relation_types[my_relation_types_prefix[rtype_key]] = set() -            for k in request_items: -                if k.startswith(rtype_key): -                    relation_types[my_relation_types_prefix[rtype_key]].add( -                        request_items[k]) -                    continue -          for k in request_keys:              val = request_items.get(k)              if not val: @@ -947,6 +938,18 @@ def get_item(model, func_name, default_name, extra_request_keys=[],          if 'search_vector' in dct:              search_vector = dct.pop('search_vector') +        # manage relations types +        if 'relation_types' not in my_relation_types_prefix: +            my_relation_types_prefix['relation_types'] = '' +        relation_types = {} +        for rtype_key in my_relation_types_prefix: +            relation_types[my_relation_types_prefix[rtype_key]] = set() +            for k in list(dct.keys()): +                if k.startswith(rtype_key): +                    relation_types[my_relation_types_prefix[rtype_key]].add( +                        dct.pop(k) +                    ) +          _manage_bool_fields(model, my_bool_fields, my_reversed_bool_fields,                              dct, or_reqs)          _manage_bool_fields(model, my_bool_fields, my_reversed_bool_fields, @@ -966,10 +969,10 @@ def get_item(model, func_name, default_name, extra_request_keys=[],          _manage_clean_search_field(dct)          _manage_clean_search_field(excluded_dct) -        query = _contruct_query(relation_types, dct, or_reqs, and_reqs) +        query = _construct_query(relation_types, dct, or_reqs, and_reqs)          exc_query = None          if excluded_dct or exc_and_reqs or exc_or_reqs: -            exc_query = _contruct_query( +            exc_query = _construct_query(                  relation_types, excluded_dct, exc_or_reqs, exc_and_reqs)          if query_own: @@ -986,7 +989,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                  upper_model, upper_key = ASSOCIATED_ITEMS[model]                  model_name = upper_model.SLUG                  current = model_name in request.session \ -                          and request.session[model_name] +                    and request.session[model_name]                  if current:                      dct = {upper_key: current}                      query &= Q(**dct)  | 
