diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-10 12:59:00 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-13 18:26:04 +0200 |
commit | 23b95b9d8de9037e40b0c79e9d0fdda1dba23d2b (patch) | |
tree | b3a79525887488ca98e4adccbcab9538c0e6f9a5 /archaeological_operations/models.py | |
parent | d643afb7db26be3a697bfd0ab1ab2239ef7b1275 (diff) | |
download | Ishtar-23b95b9d8de9037e40b0c79e9d0fdda1dba23d2b.tar.bz2 Ishtar-23b95b9d8de9037e40b0c79e9d0fdda1dba23d2b.zip |
Search administrativ act configuration
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 120 |
1 files changed, 120 insertions, 0 deletions
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: |