summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_operations/forms.py15
-rw-r--r--archaeological_operations/models.py26
-rw-r--r--ishtar_common/models.py2
-rw-r--r--ishtar_common/views_item.py81
4 files changed, 69 insertions, 55 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 866700871..63b350f28 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -524,9 +524,8 @@ class OperationSelect(TableSelect):
start_after = DateField(label=_(u"Started after"))
end_before = DateField(label=_(u"Ended before"))
end_after = DateField(label=_(u"Ended after"))
- relation_types = forms.MultipleChoiceField(
- label=_(u"Search within relations"), choices=[],
- widget=forms.CheckboxSelectMultiple)
+ relation_types = forms.ChoiceField(
+ label=_(u"Search within relations"), choices=[])
comment = forms.CharField(label=_(u"Comment"), max_length=500)
abstract = forms.CharField(label=_(u"Abstract (full text search)"))
scientific_documentation_comment = forms.CharField(
@@ -594,15 +593,7 @@ class OperationSelect(TableSelect):
k = 'towns__numero_insee__startswith'
self.fields[k].choices = [
('', '--')] + list(settings.ISHTAR_DPTS)
- self.fields['relation_types'].choices = models.RelationType.get_types(
- empty_first=False)
-
- def get_input_ids(self):
- ids = super(OperationSelect, self).get_input_ids()
- ids.pop(ids.index('relation_types'))
- for idx, c in enumerate(self.fields['relation_types'].choices):
- ids.append('relation_types_{}'.format(idx))
- return ids
+ self.fields['relation_types'].choices = models.RelationType.get_types()
class OperationFormSelection(IshtarForm):
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index dd3302251..6f083fe7f 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -410,14 +410,34 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
pgettext_lazy(TXT_SEARCH_COMMENT, u"operator"),
'operator__cached_label__iexact'
),
+ 'remains': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"remain"),
+ 'remains__pk'
+ ),
'periods': (
pgettext_lazy(TXT_SEARCH_COMMENT, u"period"),
'periods__pk'
),
- 'remains': (
- pgettext_lazy(TXT_SEARCH_COMMENT, u"remain"),
- 'remains__pk'
+ 'start_before': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"start-before"),
+ 'start_date__lte'
+ ),
+ 'start_after': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"start-after"),
+ 'start_date__gte'
+ ),
+ 'end_before': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"end-before"),
+ 'excavation_end_date__lte'
),
+ 'end_after': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"end-after"),
+ 'excavation_end_date__gte'
+ ),
+ 'relation_types': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"relation-types"),
+ 'relation_types'
+ )
}
for v in ALT_NAMES.values():
EXTRA_REQUEST_KEYS[v[0]] = v[1]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 10939deea..e2b1d5b02 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3557,7 +3557,7 @@ class Town(Imported, models.Model):
if settings.COUNTRY == "fr":
cached_label = u"%s - %s" % (self.name, self.numero_insee[:2])
if self.year and self.children.count():
- cached_label += " ({})".format(self.year)
+ cached_label += u" ({})".format(self.year)
return cached_label
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)