summaryrefslogtreecommitdiff
path: root/archaeological_operations/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r--archaeological_operations/models.py120
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: