diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-10 15:53:27 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-13 18:26:04 +0200 | 
| commit | 36b3cc6849ef3eff539d3242246a2b6aba6e5cba (patch) | |
| tree | 040e8beda76d110388d402b2fe227a7cb87e45c5 /archaeological_files/models.py | |
| parent | 36b6f6e14fffdb1efcfe62dfed6a50d2285568f7 (diff) | |
| download | Ishtar-36b3cc6849ef3eff539d3242246a2b6aba6e5cba.tar.bz2 Ishtar-36b3cc6849ef3eff539d3242246a2b6aba6e5cba.zip | |
Search file configuration
Diffstat (limited to 'archaeological_files/models.py')
| -rw-r--r-- | archaeological_files/models.py | 96 | 
1 files changed, 94 insertions, 2 deletions
| diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 5f4150695..eb4e30bde 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -24,10 +24,10 @@ from django.contrib.gis.db import models  from django.core.cache import cache  from django.db.models import Q, Count, Sum  from django.db.models.signals import post_save, m2m_changed, post_delete -from django.utils.translation import ugettext_lazy as _, ugettext +from django.utils.translation import ugettext_lazy as _, pgettext_lazy  from ishtar_common.utils import cached_label_changed, get_cache, \ -    get_current_year +    get_current_year, TXT_SEARCH_COMMENT  from ishtar_common.models import GeneralType, BaseHistorizedItem, \      HistoricalRecords, OwnPerms, Person, Organization, Department, Town, \ @@ -121,6 +121,89 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          'scientist'      ] +    # alternative names of fields for searches +    ALT_NAMES = { +        'year': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"year"), +            'year' +        ), +        'numeric_reference': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"reference"), +            'numeric_reference' +        ), +        'internal_reference': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"other-reference"), +            'internal_reference' +        ), +        'towns': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"town"), +            'towns__cached_label__iexact' +        ), +        'parcel': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"parcel"), +            'parcels__cached_label__iexact' +        ), +        'towns__numero_insee__startswith': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"department"), +            'towns__numero_insee__startswith' +        ), +        'name': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"name"), +            'name__icontains' +        ), +        'file_type': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"type"), +            'file_type__label__iexact' +        ), +        'end_date': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"active"), +            'end_date__isnull' +        ), +        'saisine_type': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"saisine-type"), +            'saisine_type__label__iexact' +        ), +        'permit_type': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"permit-type"), +            'permit_type__label__iexact' +        ), +        'permit_reference': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"permit-reference"), +            'permit_reference__iexact' +        ), +        'comment': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"comment"), +            'comment__icontains' +        ), +        'in_charge': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"in-charge"), +            'in_charge__cached_label__iexact' +        ), +        'general_contractor': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"general-contractor"), +            'general_contractor__cached_label__iexact' +        ), +        'general_contractor__attached_to': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, +                          u"general-contractor-organization"), +            'general_contractor__attached_to__cached_label__iexact' +        ), +        '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' +        ), +    } +    for v in ALT_NAMES.values(): +        EXTRA_REQUEST_KEYS[v[0]] = v[1] + +    POST_PROCESS_REQUEST = { +        'towns__numero_insee__startswith': '_get_department_code', +    } +      # fields      year = models.IntegerField(_(u"Year"), default=get_current_year)      numeric_reference = models.IntegerField( @@ -246,6 +329,15 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          )          ordering = ('cached_label',) +    @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 short_class_name(self):          return _(u"FILE") | 
