diff options
-rw-r--r-- | archaeological_files/forms.py | 31 | ||||
-rw-r--r-- | archaeological_files/models.py | 96 |
2 files changed, 106 insertions, 21 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index f78347b6c..f6c6bf48b 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -40,13 +40,15 @@ from ishtar_common.forms import FinalForm, get_now, reverse_lazy, TableSelect, \ ManageOldType, CustomForm, FieldType, IshtarForm from ishtar_common.forms_common import get_town_field from archaeological_operations.forms import AdministrativeActForm, \ - AdministrativeActOpeFormSelection, \ - ParcelField, SLICING, AdministrativeActModifForm, ParcelForm, ParcelFormSet + AdministrativeActOpeFormSelection, SLICING, AdministrativeActModifForm, \ + ParcelForm, ParcelFormSet from ishtar_common import widgets from bootstrap_datepicker.widgets import DatePicker -class FileSelect(TableSelect): +class FileSelect(TableSelect): # OK + _model = models.File + search_vector = forms.CharField( label=_(u"Full text search"), widget=widgets.SearchWidget( 'archaeological-files', 'file' @@ -56,7 +58,7 @@ class FileSelect(TableSelect): internal_reference = forms.CharField(max_length=200, label=_("Other reference")) towns = get_town_field() - parcel = ParcelField(label=_("Parcel (section/number/public domain)")) + parcel = forms.CharField(label=_(u"Parcel")) if settings.ISHTAR_DPTS: towns__numero_insee__startswith = forms.ChoiceField( label=_(u"Department"), choices=[]) @@ -105,28 +107,19 @@ class FileSelect(TableSelect): associated_model=Person), validators=[valid_id(Person)]) + TYPES = [ + FieldType('saisine_type', models.SaisineType), + FieldType('permit_type', models.PermitType), + FieldType('file_type', models.FileType), + ] + def __init__(self, *args, **kwargs): super(FileSelect, self).__init__(*args, **kwargs) - self.fields['saisine_type'].choices = \ - models.SaisineType.get_types() - self.fields['saisine_type'].help_text = models.SaisineType.get_help() - self.fields['permit_type'].choices = models.PermitType.get_types() - self.fields['permit_type'].help_text = models.PermitType.get_help() - self.fields['file_type'].choices = models.FileType.get_types() - self.fields['file_type'].help_text = models.FileType.get_help() if settings.ISHTAR_DPTS: k = 'towns__numero_insee__startswith' self.fields[k].choices = [ ('', '--')] + list(settings.ISHTAR_DPTS) - def get_input_ids(self): - ids = super(FileSelect, self).get_input_ids() - ids.pop(ids.index('parcel')) - ids.append('parcel_0') - ids.append('parcel_1') - ids.append('parcel_2') - return ids - class FileFormSelection(forms.Form): SEARCH_AND_SELECT = True 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") |