summaryrefslogtreecommitdiff
path: root/archaeological_finds/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-06-13 11:31:23 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-06-13 11:31:23 +0200
commit94cb9ad1fda2e50136f9d9e2ae8f5db7f7f81b05 (patch)
tree8aeecb3a564049016feeff684015988511f463fc /archaeological_finds/forms.py
parent2a2959c01bbcc7271d17901832cf722cd257d5d8 (diff)
downloadIshtar-94cb9ad1fda2e50136f9d9e2ae8f5db7f7f81b05.tar.bz2
Ishtar-94cb9ad1fda2e50136f9d9e2ae8f5db7f7f81b05.zip
Find search: now a custom form
Diffstat (limited to 'archaeological_finds/forms.py')
-rw-r--r--archaeological_finds/forms.py85
1 files changed, 37 insertions, 48 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 45e8342e7..41ecb5d31 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -50,11 +50,10 @@ from archaeological_operations.widgets import OAWidget
from archaeological_warehouse.models import Warehouse
from bootstrap_datepicker.widgets import DatePicker
from ishtar_common import widgets
-from ishtar_common.forms import FormSet, FloatField, \
- reverse_lazy, TableSelect, get_now, FinalForm, \
+from ishtar_common.forms import CustomForm, CustomFormSearch, FormSet, \
+ FloatField, reverse_lazy, TableSelect, get_now, FinalForm, \
ManageOldType, FieldType, IshtarForm, FormHeader
-from ishtar_common.forms_common import get_town_field, \
- CustomForm
+from ishtar_common.forms_common import get_town_field
from ishtar_common.models import valid_id, valid_ids, get_current_profile, \
SpatialReferenceSystem
from ishtar_common.utils import convert_coordinates_to_point
@@ -406,7 +405,9 @@ DatingFormSet.form_admin_name = _(u"Find - 040 - Dating")
DatingFormSet.form_slug = "find-040-dating"
-class FindSelect(TableSelect):
+class FindSelect(CustomForm, TableSelect):
+ form_admin_name = _(u"Find - 001 - Search")
+ form_slug = "find-001-search"
search_vector = forms.CharField(label=_(u"Full text search"),
widget=widgets.SearchWidget)
base_finds__cache_short_id = forms.CharField(label=_(u"Short ID"))
@@ -463,53 +464,40 @@ class FindSelect(TableSelect):
checked = forms.ChoiceField(label=_("Check"))
documents__image__isnull = forms.NullBooleanField(label=_(u"Has an image?"))
+ TYPES = [
+ FieldType('datings__period', Period),
+ FieldType('material_types', models.MaterialType),
+ FieldType('conservatory_state', models.ConservatoryState),
+ FieldType('base_finds__batch', models.BatchType),
+ FieldType('object_types', models.ObjectType),
+ FieldType('preservation_to_considers', models.TreatmentType),
+ FieldType('integrities', models.IntegrityType),
+ FieldType('remarkabilities', models.RemarkabilityType),
+
+ ]
+
def __init__(self, *args, **kwargs):
super(FindSelect, self).__init__(*args, **kwargs)
- self.fields['datings__period'].choices = Period.get_types()
- self.fields['datings__period'].help_text = Period.get_help()
- self.fields['material_types'].choices = \
- models.MaterialType.get_types()
- self.fields['material_types'].help_text = \
- models.MaterialType.get_help()
- self.fields['conservatory_state'].choices = \
- models.ConservatoryState.get_types()
- self.fields['conservatory_state'].help_text = \
- models.ConservatoryState.get_help()
-
- self.fields['base_finds__batch'].choices = \
- models.BatchType.get_types()
- self.fields['base_finds__batch'].help_text = \
- models.BatchType.get_help()
-
- self.fields['object_types'].choices = \
- models.ObjectType.get_types()
- self.fields['checked'].choices = \
- [('', '--')] + list(models.CHECK_CHOICES)
- self.fields['preservation_to_considers'].choices = \
- models.TreatmentType.get_types()
- self.fields['preservation_to_considers'].help_text = \
- models.TreatmentType.get_help()
- self.fields['integrities'].choices = \
- models.IntegrityType.get_types()
- self.fields['integrities'].help_text = \
- models.IntegrityType.get_help()
- self.fields['remarkabilities'].choices = \
- models.RemarkabilityType.get_types()
- self.fields['remarkabilities'].help_text = \
- models.RemarkabilityType.get_help()
- self.fields['ope_relation_types'].choices = OpeRelationType.get_types(
- empty_first=False)
- self.fields['cr_relation_types'].choices = CRRelationType.get_types(
- empty_first=False)
+ if 'checked' in self.fields:
+ self.fields['checked'].choices = \
+ [('', '--')] + list(models.CHECK_CHOICES)
+ if 'ope_relation_types' in self.fields:
+ self.fields['ope_relation_types'].choices = \
+ OpeRelationType.get_types(empty_first=False)
+ if 'cr_relation_types' in self.fields:
+ self.fields['cr_relation_types'].choices = CRRelationType.get_types(
+ empty_first=False)
def get_input_ids(self):
ids = super(FindSelect, self).get_input_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))
- 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))
+ 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))
return ids
@@ -530,11 +518,12 @@ class FindSelectWarehouseModule(FindSelect):
container__reference = forms.IntegerField(label=_(u"Container ref."))
-class FindFormSelection(forms.Form):
+class FindFormSelection(CustomFormSearch):
SEARCH_AND_SELECT = True
form_label = _("Find search")
associated_models = {'pk': models.Find}
currents = {'pk': models.Find}
+
pk = forms.IntegerField(
label="", required=False,
widget=widgets.DataTable(