summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_files/forms.py22
-rw-r--r--archaeological_operations/forms.py18
-rw-r--r--archaeological_operations/models.py120
-rw-r--r--ishtar_common/views_item.py178
4 files changed, 232 insertions, 106 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index 645953a78..f78347b6c 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -408,7 +408,9 @@ class FinalFileDeleteForm(FinalForm):
confirm_end_msg = _(u"Would you like to delete this archaeological file ?")
-class AdministrativeActFileModifySelect(TableSelect):
+class AdministrativeActFileModifySelect(TableSelect): # OK
+ _model = AdministrativeAct
+
search_vector = forms.CharField(
label=_(u"Full text search"), widget=widgets.SearchWidget(
'archaeological-operations', 'administrativeact'
@@ -439,7 +441,9 @@ class AdministrativeActFileModifySelect(TableSelect):
('', '--')] + list(settings.ISHTAR_DPTS)
-class AdministrativeActFileSelect(TableSelect):
+class AdministrativeActFileSelect(TableSelect): # OK
+ _model = AdministrativeAct
+
search_vector = forms.CharField(
label=_(u"Full text search"), widget=widgets.SearchWidget(
'archaeological-operations', 'administrativeact'
@@ -452,17 +456,17 @@ class AdministrativeActFileSelect(TableSelect):
act_type = forms.ChoiceField(label=_("Act type"), choices=[])
indexed = forms.NullBooleanField(label=_(u"Indexed?"))
associated_file__towns = get_town_field()
- parcel = ParcelField(label=_("Parcel (section/number/public domain)"))
+ parcel = forms.CharField(label=_(u"Parcel"))
if settings.ISHTAR_DPTS:
associated_file__towns__numero_insee__startswith = forms.ChoiceField(
label=_(u"Department"), choices=[])
act_object = forms.CharField(label=_(u"Object"),
max_length=300)
- signature_date_after = forms.DateField(
- label=_(u"Signature date after"), widget=DatePicker)
signature_date_before = forms.DateField(
label=_(u"Signature date before"), widget=DatePicker)
+ signature_date_after = forms.DateField(
+ label=_(u"Signature date after"), widget=DatePicker)
associated_file__name = forms.CharField(
label=_(u"File name"), max_length=200)
associated_file__general_contractor = forms.IntegerField(
@@ -523,14 +527,6 @@ class AdministrativeActFileSelect(TableSelect):
self.fields[k].choices = [
('', '--')] + list(settings.ISHTAR_DPTS)
- def get_input_ids(self):
- ids = super(AdministrativeActFileSelect, self).get_input_ids()
- ids.pop(ids.index('parcel'))
- ids.append('parcel_0')
- ids.append('parcel_1')
- ids.append('parcel_2')
- return ids
-
class AdministrativeActFileFormSelection(AdministrativeActOpeFormSelection):
SEARCH_AND_SELECT = True
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index dc389c81c..d57a890eb 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -471,7 +471,7 @@ RecordRelationsFormSet.form_admin_name = _(u"Operation - 080 - Relations")
RecordRelationsFormSet.form_slug = "operation-080-relations"
-class OperationSelect(TableSelect):
+class OperationSelect(TableSelect): # OK
_model = models.Operation
search_vector = forms.CharField(
@@ -1230,7 +1230,7 @@ class OperationDeletionForm(FinalForm):
#########
-class SiteSelect(TableSelect):
+class SiteSelect(TableSelect): # OK
_model = models.ArchaeologicalSite
search_vector = forms.CharField(
@@ -1376,7 +1376,9 @@ class SiteUnderwaterForm(ManageOldType):
################################################
-class AdministrativeActOpeSelect(TableSelect):
+class AdministrativeActOpeSelect(TableSelect): # OK
+ _model = models.AdministrativeAct
+
search_vector = forms.CharField(
label=_(u"Full text search"), widget=widgets.SearchWidget(
'archaeological-operations', 'administrativeact'
@@ -1393,7 +1395,7 @@ class AdministrativeActOpeSelect(TableSelect):
act_type = forms.ChoiceField(label=_("Act type"), choices=[])
indexed = forms.NullBooleanField(label=_(u"Indexed?"))
operation__towns = get_town_field()
- parcel = ParcelField(label=_("Parcel (section/number/public domain)"))
+ parcel = forms.CharField(label=_(u"Parcel"))
if settings.ISHTAR_DPTS:
operation__towns__numero_insee__startswith = forms.ChoiceField(
label=_(u"Department"), choices=[])
@@ -1424,14 +1426,6 @@ class AdministrativeActOpeSelect(TableSelect):
self.fields[k].choices = [
('', '--')] + list(settings.ISHTAR_DPTS)
- def get_input_ids(self):
- ids = super(AdministrativeActOpeSelect, self).get_input_ids()
- ids.pop(ids.index('parcel'))
- ids.append('parcel_0')
- ids.append('parcel_1')
- ids.append('parcel_2')
- return ids
-
class AdministrativeActOpeFormSelection(IshtarForm):
SEARCH_AND_SELECT = True
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 8fa00a215..082bbd2fe 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -1370,6 +1370,117 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
PARENT_SEARCH_VECTORS = ['operator', 'scientist', 'signatory',
'associated_file', 'operation', 'treatment_file',
'treatment']
+ # alternative names of fields for searches
+ ALT_NAMES = {
+ 'year': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"year"),
+ 'signature_date__year'
+ ),
+ 'index': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"index"),
+ 'index'
+ ),
+ 'ref_sra': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"other-ref"),
+ 'ref_sra__iexact'
+ ),
+ 'operation__code_patriarche': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"patriarche"),
+ 'operation__code_patriarche'
+ ),
+ 'act_type': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"type"),
+ 'act_type__label__iexact'
+ ),
+ 'indexed': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"indexed"),
+ 'index__isnull'
+ ),
+ 'operation__towns': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-town"),
+ 'operation__towns__cached_label__iexact'
+ ),
+ 'associated_file__towns': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"file-town"),
+ 'associated_file__towns__cached_label__iexact'
+ ),
+ 'parcel': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"parcel"),
+ ('associated_file__parcels__cached_label__iexact',
+ 'operation__parcels__cached_label__iexact',
+ 'operation__associated_file__parcels__cached_label__iexact'),
+ ),
+ 'operation__towns__numero_insee__startswith': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-department"),
+ 'operation__towns__numero_insee__startswith'
+ ),
+ 'associated_file__towns__numero_insee__startswith': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"file-department"),
+ 'associated_file__towns__numero_insee__startswith'
+ ),
+ 'act_object': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"object"),
+ 'act_object__icontains'
+ ),
+ 'history_creator': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"created-by"),
+ 'history_creator__ishtaruser__person__cached_label__iexact'
+ ),
+ 'history_modifier': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"modified-by"),
+ 'history_modifier__ishtaruser__person__cached_label__iexact'
+ ),
+ 'signature_date_before': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"signature-before"),
+ 'signature_date__lte'
+ ),
+ 'signature_date_after': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"signature-after"),
+ 'signature_date__gte'
+ ),
+ 'associated_file__name': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"file-name"),
+ 'associated_file__name__icontains'
+ ),
+ 'associated_file__general_contractor': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"general-contractor"),
+ 'associated_file__general_contractor__cached_label__iexact'
+ ),
+ 'associated_file__general_contractor__attached_to': (
+ pgettext_lazy(TXT_SEARCH_COMMENT,
+ u"general-contractor-organization"),
+ 'associated_file__general_contractor__attached_to'
+ '__cached_label__iexact'
+ ),
+ 'associated_file__numeric_reference': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"file-reference"),
+ 'associated_file__numeric_reference'
+ ),
+ 'associated_file__year': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"file-year"),
+ 'associated_file__year'
+ ),
+ 'associated_file__internal_reference': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"file-other-reference"),
+ 'associated_file__internal_reference__iexact'
+ ),
+ 'associated_file__in_charge': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"file-in-charge"),
+ 'associated_file__in_charge__cached_label__iexact'
+ ),
+ 'associated_file__permit_reference': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"file-permit-reference"),
+ 'associated_file__permit_reference__iexact'
+ ),
+ }
+ for v in ALT_NAMES.values():
+ EXTRA_REQUEST_KEYS[v[0]] = v[1]
+
+ POST_PROCESS_REQUEST = {
+ 'operation__towns__numero_insee__startswith': '_get_department_code',
+ 'associated_file__towns__numero_insee__startswith':
+ '_get_department_code',
+ }
# fields
act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
@@ -1492,6 +1603,15 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
dpts.append(dpt)
return ', '.join(list(sorted(dpts)))
+ @classmethod
+ def _get_department_code(cls, value):
+ if not settings.ISHTAR_DPTS:
+ return u""
+ for k, v in settings.ISHTAR_DPTS:
+ if v.lower() == value:
+ return k
+ return u""
+
@property
def related_item(self):
if self.operation:
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 3b09bc7da..1a0ef61e7 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -537,88 +537,91 @@ def _manage_facet_search(model, dct, and_reqs):
def _manage_hierarchic_fields(dct, and_reqs):
- for req in dct.copy():
- if req.endswith('areas__pk'):
- val = _clean_type_val(dct.pop(req))
- reqs = Q(**{req: val})
- base_req = req[:-2] + '__'
- req = base_req[:]
- for idx in range(HIERARCHIC_LEVELS):
- req = req[:-2] + 'parent__pk'
- q = Q(**{req: val})
- reqs |= q
- req = base_req[:]
- for idx in range(HIERARCHIC_LEVELS):
- req = req[:-2] + 'children__pk'
- q = Q(**{req: val})
- reqs |= q
- and_reqs.append(reqs)
- continue
-
- if req.endswith('town__pk') or req.endswith('towns__pk'):
- val = _clean_type_val(dct.pop(req))
- reqs = Q(**{req: val})
- base_req = req[:-2] + '__'
- req = base_req[:]
- for idx in range(HIERARCHIC_LEVELS):
- req = req[:-2] + 'parents__pk'
- q = Q(**{req: val})
- reqs |= q
- req = base_req[:]
- for idx in range(HIERARCHIC_LEVELS):
- req = req[:-2] + 'children__pk'
- q = Q(**{req: val})
- reqs |= q
- and_reqs.append(reqs)
- continue
+ for reqs in dct.copy():
+ if type(reqs) not in (list, tuple):
+ reqs = [reqs]
+ for req in reqs:
+ if req.endswith('areas__pk'):
+ val = _clean_type_val(dct.pop(req))
+ reqs = Q(**{req: val})
+ base_req = req[:-2] + '__'
+ req = base_req[:]
+ for idx in range(HIERARCHIC_LEVELS):
+ req = req[:-2] + 'parent__pk'
+ q = Q(**{req: val})
+ reqs |= q
+ req = base_req[:]
+ for idx in range(HIERARCHIC_LEVELS):
+ req = req[:-2] + 'children__pk'
+ q = Q(**{req: val})
+ reqs |= q
+ and_reqs.append(reqs)
+ continue
- for k_hr in HIERARCHIC_FIELDS:
- if type(req) in (list, tuple):
- val = dct.pop(req)
- q = None
- for idx, r in enumerate(req):
- r = _clean_type_val(r)
- if not idx:
- q = Q(**{r: val})
- else:
- q |= Q(**{r: val})
- and_reqs.append(q)
- break
- elif req.endswith(k_hr + '__pk'):
+ if req.endswith('town__pk') or req.endswith('towns__pk'):
val = _clean_type_val(dct.pop(req))
+ reqs = Q(**{req: val})
+ base_req = req[:-2] + '__'
+ req = base_req[:]
+ for idx in range(HIERARCHIC_LEVELS):
+ req = req[:-2] + 'parents__pk'
+ q = Q(**{req: val})
+ reqs |= q
+ req = base_req[:]
+ for idx in range(HIERARCHIC_LEVELS):
+ req = req[:-2] + 'children__pk'
+ q = Q(**{req: val})
+ reqs |= q
+ and_reqs.append(reqs)
+ continue
- if u";" in val:
- # OR request
- values = val.split(u";")
- else:
- values = [val]
- base_req = req[:]
- reqs = None
- for val in values:
- suffix = "pk"
- req = base_req[:]
-
- if val.startswith(u'"') and val.startswith(u'"'):
- # manage search text by label
- if u"*" in val:
- suffix = "label__icontains"
- val = val.replace(u'*', u"")
+ for k_hr in HIERARCHIC_FIELDS:
+ if type(req) in (list, tuple):
+ val = dct.pop(req)
+ q = None
+ for idx, r in enumerate(req):
+ r = _clean_type_val(r)
+ if not idx:
+ q = Q(**{r: val})
else:
- suffix = "label__iexact"
- val = val[1:-1]
- req = req[:-2] + suffix
+ q |= Q(**{r: val})
+ and_reqs.append(q)
+ break
+ elif req.endswith(k_hr + '__pk'):
+ val = _clean_type_val(dct.pop(req))
- if not reqs:
- reqs = Q(**{req: val})
+ if u";" in val:
+ # OR request
+ values = val.split(u";")
else:
- reqs |= Q(**{req: val})
- for idx in range(HIERARCHIC_LEVELS):
- req = req[:-(len(suffix))] + 'parent__' + suffix
- q = Q(**{req: val})
- reqs |= q
- if reqs:
- and_reqs.append(reqs)
- break
+ values = [val]
+ base_req = req[:]
+ reqs = None
+ for val in values:
+ suffix = "pk"
+ req = base_req[:]
+
+ if val.startswith(u'"') and val.startswith(u'"'):
+ # manage search text by label
+ if u"*" in val:
+ suffix = "label__icontains"
+ val = val.replace(u'*', u"")
+ else:
+ suffix = "label__iexact"
+ val = val[1:-1]
+ req = req[:-2] + suffix
+
+ if not reqs:
+ reqs = Q(**{req: val})
+ else:
+ reqs |= Q(**{req: val})
+ for idx in range(HIERARCHIC_LEVELS):
+ req = req[:-(len(suffix))] + 'parent__' + suffix
+ q = Q(**{req: val})
+ reqs |= q
+ if reqs:
+ and_reqs.append(reqs)
+ break
def _manage_clean_search_field(dct):
@@ -689,6 +692,16 @@ def _construct_query(relation_types, dct, or_reqs, and_reqs):
(key, {key: v})
)
+ for k in list(dct.keys()):
+ if type(k) not in (list, tuple):
+ continue
+ first_key = k[0]
+ value = dct[k][:]
+ dct.pop(k)
+ dct[first_key] = value
+ for other_key in k[1:]:
+ or_reqs.append((first_key, {other_key: value}))
+
query = Q(**dct)
for k, or_req in or_reqs:
alt_dct = dct.copy()
@@ -952,11 +965,14 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
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)
- )
+ for keys in list(dct.keys()):
+ if type(keys) not in (list, tuple):
+ keys = [keys]
+ for k in 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)