diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-13 09:49:09 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-13 09:49:09 +0200 |
commit | 077dea01ed2d9afc97412631e4207eaf4175e06d (patch) | |
tree | 57a32eeff03668f481cbd91ccd6803e56666b36d /archaeological_context_records/forms.py | |
parent | e3ff6616d2596a4e8d8fa83c1382c48d89fbc9dd (diff) | |
download | Ishtar-077dea01ed2d9afc97412631e4207eaf4175e06d.tar.bz2 Ishtar-077dea01ed2d9afc97412631e4207eaf4175e06d.zip |
Custom forms: manage customization of search forms
Diffstat (limited to 'archaeological_context_records/forms.py')
-rw-r--r-- | archaeological_context_records/forms.py | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 3238eb771..acfb47d2a 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -38,7 +38,7 @@ from bootstrap_datepicker.widgets import DatePicker from ishtar_common import widgets from ishtar_common.forms import FinalForm, FormSet, \ reverse_lazy, get_form_selection, TableSelect, ManageOldType, CustomForm, \ - FieldType + FieldType, CustomFormSearch from ishtar_common.forms_common import get_town_field from ishtar_common.models import valid_id, IshtarSiteProfile, Town @@ -57,7 +57,9 @@ class OperationFormSelection(CustomForm, forms.Form): validators=[valid_id(Operation)]) -class RecordSelect(TableSelect): +class RecordSelect(CustomForm, TableSelect): + form_admin_name = _(u"Context record - 001 - Search") + form_slug = "contextrecord-001-search" search_vector = forms.CharField(label=_(u"Full text search"), widget=widgets.SearchWidget) label = forms.CharField(label=_(u"ID"), max_length=100) @@ -88,33 +90,41 @@ class RecordSelect(TableSelect): def __init__(self, *args, **kwargs): super(RecordSelect, self).__init__(*args, **kwargs) - self.fields['datings__period'].choices = Period.get_types() - self.fields['datings__period'].help_text = Period.get_help() - self.fields['unit'].choices = models.Unit.get_types() - self.fields['unit'].help_text = models.Unit.get_help() - self.fields['cr_relation_types'].choices = \ - models.RelationType.get_types(empty_first=False) - self.fields['ope_relation_types'].choices = OpeRelationType.get_types( - empty_first=False) + if 'datings__period' in self.fields: + self.fields['datings__period'].choices = Period.get_types() + self.fields['datings__period'].help_text = Period.get_help() + if 'unit' in self.fields: + self.fields['unit'].choices = models.Unit.get_types() + self.fields['unit'].help_text = models.Unit.get_help() + if 'cr_relation_types' in self.fields: + self.fields['cr_relation_types'].choices = \ + models.RelationType.get_types(empty_first=False) + if 'ope_relation_types' in self.fields: + self.fields['ope_relation_types'].choices = \ + OpeRelationType.get_types(empty_first=False) def get_input_ids(self): ids = super(RecordSelect, self).get_input_ids() - ids.pop(ids.index('parcel')) - ids.append('parcel_0') - ids.append('parcel_1') - ids.append('parcel_2') - ids.pop(ids.index('cr_relation_types')) - for idx, c in enumerate(self.fields['cr_relation_types'].choices): - ids.append('cr_relation_types_{}'.format(idx)) - ids.pop(ids.index('ope_relation_types')) - for idx, c in enumerate(self.fields['ope_relation_types'].choices): - ids.append('ope_relation_types_{}'.format(idx)) + if 'parcel' in ids: + ids.pop(ids.index('parcel')) + ids.append('parcel_0') + ids.append('parcel_1') + ids.append('parcel_2') + if 'cr_relation_types' in ids: + ids.pop(ids.index('cr_relation_types')) + for idx, c in enumerate(self.fields['cr_relation_types'].choices): + ids.append('cr_relation_types_{}'.format(idx)) + if 'ope_relation_types' in ids: + ids.pop(ids.index('ope_relation_types')) + for idx, c in enumerate(self.fields['ope_relation_types'].choices): + ids.append('ope_relation_types_{}'.format(idx)) return ids -class RecordFormSelection(forms.Form): +class RecordFormSelection(CustomFormSearch): form_label = _("Context record search") SEARCH_AND_SELECT = True + associated_models = {'pk': models.ContextRecord} currents = {'pk': models.ContextRecord} pk = forms.IntegerField( |