diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-09 19:02:49 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-13 18:26:04 +0200 |
commit | d643afb7db26be3a697bfd0ab1ab2239ef7b1275 (patch) | |
tree | 717f96c1a9bae8c8f81b0a3ab4358cc0b767cbb6 | |
parent | 03452f53b22c55c0b527d76433dbbd7dc52fe6dc (diff) | |
download | Ishtar-d643afb7db26be3a697bfd0ab1ab2239ef7b1275.tar.bz2 Ishtar-d643afb7db26be3a697bfd0ab1ab2239ef7b1275.zip |
Adapt search form for sites
-rw-r--r-- | archaeological_operations/forms.py | 33 | ||||
-rw-r--r-- | archaeological_operations/models.py | 63 |
2 files changed, 96 insertions, 0 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index af4e21e31..dc389c81c 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -1231,6 +1231,8 @@ class OperationDeletionForm(FinalForm): class SiteSelect(TableSelect): + _model = models.ArchaeologicalSite + search_vector = forms.CharField( label=_(u"Full text search"), widget=widgets.SearchWidget( 'archaeological-operations', 'archaeologicalsite')) @@ -1239,11 +1241,42 @@ class SiteSelect(TableSelect): name = forms.CharField(label=_(u"Name"), max_length=200, required=False) periods = forms.ChoiceField(label=_(u"Periods"), choices=[], required=False) remains = forms.ChoiceField(label=_(u"Remains"), choices=[], required=False) + towns = get_town_field() + comment = forms.CharField(label=_(u"Comment"), max_length=200, + required=False) + locality_ngi = forms.CharField( + label=_(u"National Geographic Institute locality"), max_length=200, + required=False) + locality_cadastral = forms.CharField( + label=_(u"Cadastral locality"), max_length=200, + required=False) + shipwreck_name = forms.CharField( + label=_(u"Shipwreck name"), max_length=200, + required=False) + oceanographic_service_localisation = forms.CharField( + label=_(u"Oceanographic service localisation"), max_length=200, + required=False) + shipwreck_code = forms.CharField( + label=_(u"Shipwreck code"), max_length=200, + required=False) + sinking_date = DateField(label=_(u"Sinking date"), required=False) + discovery_area = forms.CharField( + label=_(u"Discovery area"), max_length=200, + required=False) TYPES = [ FieldType('periods', models.Period), FieldType('remains', models.RemainType), ] + def __init__(self, *args, **kwargs): + super(SiteSelect, self).__init__(*args, **kwargs) + if not get_current_profile().underwater: + self.fields.pop('shipwreck_name') + self.fields.pop('oceanographic_service_localisation') + self.fields.pop('shipwreck_code') + self.fields.pop('sinking_date') + self.fields.pop('discovery_area') + class SiteFormSelection(IshtarForm): SEARCH_AND_SELECT = True diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index f09184a32..8fa00a215 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -116,6 +116,69 @@ class ArchaeologicalSite(BaseHistorizedItem): M2M_SEARCH_VECTORS = ["periods__label", "remains__label", "towns__name"] PARENT_SEARCH_VECTORS = ['operations'] + DATED_FIELDS = ['sinking_date'] + + EXTRA_REQUEST_KEYS = {} + + # alternative names of fields for searches + ALT_NAMES = { + 'reference': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"reference"), + 'reference' + ), + 'name': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"name"), + 'name' + ), + 'periods': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"period"), + 'periods__label__iexact' + ), + 'remains': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"remain"), + 'remains__label__iexact' + ), + 'towns': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"town"), + 'towns__cached_label__iexact' + ), + 'comment': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"comment"), + 'comment__icontains' + ), + 'locality_ngi': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"locality-ngi"), + 'locality_ngi__icontains' + ), + 'locality_cadastral': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"locality-cadastral"), + 'locality_cadastral__icontains' + ), + 'shipwreck_name': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"shipwreck-name"), + 'shipwreck_name__iexact' + ), + 'oceanographic_service_localisation': ( + pgettext_lazy(TXT_SEARCH_COMMENT, + u"oceanographic-service-localisation"), + 'oceanographic_service_localisation__icontains' + ), + 'shipwreck_code': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"shipwreck-code"), + 'shipwreck_code__iexact' + ), + 'sinking_date': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"sinking-date"), + 'sinking_date' + ), + 'discovery_area': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"discovery-area"), + 'discovery_area__icontains' + ), + } + for v in ALT_NAMES.values(): + EXTRA_REQUEST_KEYS[v[0]] = v[1] + reference = models.CharField(_(u"Reference"), max_length=200, unique=True) name = models.CharField(_(u"Name"), max_length=200, null=True, blank=True) |