diff options
Diffstat (limited to 'archaeological_operations')
| -rw-r--r-- | archaeological_operations/forms.py | 18 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 120 | 
2 files changed, 126 insertions, 12 deletions
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:  | 
