summaryrefslogtreecommitdiff
path: root/archaeological_context_records/forms.py
diff options
context:
space:
mode:
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
commitb8b8b561ea52729d54c3ea44cc6b6a05450f9dcb (patch)
tree57a32eeff03668f481cbd91ccd6803e56666b36d /archaeological_context_records/forms.py
parent003c37f1a2c31da847435b425e4755dc4fb58e15 (diff)
downloadIshtar-b8b8b561ea52729d54c3ea44cc6b6a05450f9dcb.tar.bz2
Ishtar-b8b8b561ea52729d54c3ea44cc6b6a05450f9dcb.zip
Custom forms: manage customization of search forms
Diffstat (limited to 'archaeological_context_records/forms.py')
-rw-r--r--archaeological_context_records/forms.py52
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(