From 32b9575cefa9eede2be68ea8464a7c70d52e4105 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 14 Feb 2018 12:39:03 +0100 Subject: Archaeological site: search view (refs #3913) - add site to profile - allow alternate label in menus for sites - add entry in menu - basic configuration of site model --- archaeological_operations/forms.py | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'archaeological_operations/forms.py') diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 4f5ac0435..38efb269f 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -1245,6 +1245,49 @@ class OperationDeletionForm(FinalForm): confirm_msg = " " confirm_end_msg = _(u"Would you like to delete this operation?") +######### +# Sites # +######### + + +class SiteSelect(TableSelect): + search_vector = forms.CharField(label=_(u"Full text search")) + reference = forms.CharField(label=_(u"Reference"), max_length=200, + required=False) + 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) + TYPES = [ + FieldType('periods', models.Period), + FieldType('remains', models.RemainType), + ] + + +class SiteFormSelection(IshtarForm): + SEARCH_AND_SELECT = True + associated_models = {'pk': models.ArchaeologicalSite} + currents = {'pk': models.ArchaeologicalSite} + pk = forms.IntegerField( + label="", required=False, + widget=widgets.DataTable( + reverse_lazy('get-site'), SiteSelect, + models.ArchaeologicalSite, + source_full=reverse_lazy('get-site-full')), + validators=[valid_id(models.Operation)]) + + @classmethod + def form_label(cls): + return unicode(_(u"{} search")).format( + get_current_profile().get_site_label() + ) + + def clean(self): + cleaned_data = self.cleaned_data + if 'pk' not in cleaned_data or not cleaned_data['pk']: + raise forms.ValidationError(_(u"You should select an item.")) + return cleaned_data + + #################################### # Source management for operations # #################################### -- cgit v1.2.3