summaryrefslogtreecommitdiff
path: root/archaeological_finds/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/forms.py')
-rw-r--r--archaeological_finds/forms.py166
1 files changed, 111 insertions, 55 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 958b1896c..970b35f92 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -72,11 +72,12 @@ __all__ = [
'AdministrativeActTreatmentFormSelection',
'AdministrativeActTreatmentFileModifForm',
'DashboardTreatmentForm', 'DashboardTreatmentFileForm',
- 'RecordFormSelection', 'FindForm', 'DateForm', 'DatingFormSet',
- 'PreservationForm', 'FindBasketFormSelection', 'FindBasketForm',
- 'FindSelect', 'FindFormSelection', 'FindFormSelectionWarehouseModule',
- 'MultipleFindFormSelection', 'MultipleFindFormSelectionWarehouseModule',
- 'FindMultipleFormSelection', 'check_form', 'check_exist', 'check_not_exist',
+ 'RecordFormSelection', 'FindForm', 'SimpleFindForm', 'DateForm',
+ 'DatingFormSet', 'PreservationForm', 'FindBasketFormSelection',
+ 'FindBasketForm', 'FindSelect', 'FindFormSelection',
+ 'FindFormSelectionWarehouseModule', 'MultipleFindFormSelection',
+ 'MultipleFindFormSelectionWarehouseModule', 'FindMultipleFormSelection',
+ 'check_form', 'check_exist', 'check_not_exist',
'check_value', 'check_type_field', 'check_type_not_field',
'check_treatment', 'ResultFindForm', 'ResultFindFormSet',
'FindDeletionForm', 'UpstreamFindFormSelection', 'NewFindBasketForm',
@@ -123,23 +124,33 @@ class RecordFormSelection(CustomForm, forms.Form):
cr.operation.pk)
-class FindForm(CustomForm, ManageOldType):
+class BaseFindForm(CustomForm, ManageOldType):
+ """
+ Base find form with no field related to base_find
+ """
file_upload = True
form_label = _("Find")
- form_admin_name = _(u"Find - 020 - General")
- form_slug = "find-020-general"
- base_models = ['get_first_base_find', 'object_type', 'material_type',
- 'communicabilitie']
+ form_admin_name = _(u"Simple find - 020 - General")
+ form_slug = "simplefind-020-general"
+ base_models = ['object_type', 'material_type', 'communicabilitie']
associated_models = {
'material_type': models.MaterialType,
'object_type': models.ObjectType,
'communicabilitie': models.CommunicabilityType,
- 'get_first_base_find__batch': models.BatchType,
- 'get_first_base_find__spatial_reference_system': SpatialReferenceSystem,
'material_type_quality': models.MaterialTypeQualityType,
'object_type_quality': models.ObjectTypeQualityType,
'checked_type': models.CheckedType,
}
+ field_order = [
+ 'label', 'denomination', 'previous_id', 'museum_id', 'seal_number',
+ 'mark', 'description', 'is_complete', 'material_type',
+ 'material_type_quality', 'object_type', 'object_type_quality',
+ 'find_number', 'min_number_of_individuals', 'inscription',
+ 'manufacturing_place', 'communicabilitie', 'comment', 'dating_comment',
+ 'length', 'width', 'height', 'diameter', 'thickness', 'volume',
+ 'weight', 'clutter_long_side', 'clutter_short_side', 'clutter_height',
+ 'dimensions_comment', 'checked_type', 'check_date'
+ ]
HEADERS = {}
HEADERS['label'] = FormHeader(_(u"Identification"))
@@ -148,8 +159,6 @@ class FindForm(CustomForm, ManageOldType):
validators=[validators.MaxLengthValidator(60)])
denomination = forms.CharField(label=_(u"Denomination"), required=False)
previous_id = forms.CharField(label=_("Previous ID"), required=False)
- get_first_base_find__excavation_id = forms.CharField(
- label=_(u"Excavation ID"), required=False)
museum_id = forms.CharField(label=_(u"Museum ID"), required=False)
seal_number = forms.CharField(label=_(u"Seal number"), required=False)
mark = forms.CharField(label=_(u"Mark"), required=False)
@@ -157,14 +166,6 @@ class FindForm(CustomForm, ManageOldType):
HEADERS['description'] = FormHeader(_(u"Description"))
description = forms.CharField(label=_(u"Description"),
widget=forms.Textarea, required=False)
- get_first_base_find__discovery_date = forms.DateField(
- label=_(u"Discovery date (exact or TPQ)"), widget=DatePicker,
- required=False)
- get_first_base_find__discovery_date_taq = forms.DateField(
- label=_(u"Discovery date (TAQ)"), widget=DatePicker, required=False)
- get_first_base_find__batch = forms.ChoiceField(
- label=_(u"Batch/object"), choices=[],
- required=False)
is_complete = forms.NullBooleanField(label=_(u"Is complete?"),
required=False)
material_type = widgets.Select2MultipleField(
@@ -212,8 +213,86 @@ class FindForm(CustomForm, ManageOldType):
dimensions_comment = forms.CharField(
label=_(u"Dimensions comment"), required=False, widget=forms.Textarea)
- HEADERS['get_first_base_find__x'] = FormHeader(
- _(u"Coordinates"))
+ HEADERS['checked_type'] = FormHeader(_(u"Sheet"))
+ checked_type = forms.ChoiceField(label=_(u"Check"), required=False)
+ check_date = forms.DateField(
+ initial=get_now, label=_(u"Check date"), widget=DatePicker)
+
+ TYPES = [
+ FieldType('material_type', models.MaterialType, is_multiple=True),
+ FieldType('material_type_quality', models.MaterialTypeQualityType),
+ FieldType('object_type', models.ObjectType, is_multiple=True),
+ FieldType('object_type_quality', models.ObjectTypeQualityType),
+ FieldType('communicabilitie', models.CommunicabilityType,
+ is_multiple=True),
+ FieldType('checked_type', models.CheckedType, is_multiple=True),
+ ]
+
+ def __init__(self, *args, **kwargs):
+ context_record = kwargs.pop('context_record')
+ super(BaseFindForm, self).__init__(*args, **kwargs)
+ if not context_record or \
+ not context_record.operation.operation_type.judiciary:
+ self.fields.pop('seal_number')
+
+ def clean(self):
+ clutter_long_side = self.cleaned_data.get('clutter_long_side', None)
+ clutter_short_side = self.cleaned_data.get('clutter_short_side', None)
+
+ if clutter_long_side and clutter_short_side and \
+ clutter_short_side > clutter_long_side:
+ raise forms.ValidationError(
+ unicode(_(
+ u"Clutter: short side cannot be bigger than the long side."
+ ))
+ )
+ return self.cleaned_data
+
+
+class FindForm(BaseFindForm):
+ file_upload = True
+ form_label = _("Find")
+ form_admin_name = _(u"Find - 020 - General")
+ form_slug = "find-020-general"
+ base_models = ['get_first_base_find'] + BaseFindForm.base_models
+ associated_models = BaseFindForm.associated_models.copy()
+ associated_models.update({
+ 'get_first_base_find__batch': models.BatchType,
+ 'get_first_base_find__spatial_reference_system': SpatialReferenceSystem,
+ })
+ field_order = [
+ 'label', 'denomination', 'previous_id',
+ 'get_first_base_find__excavation_id', 'museum_id', 'seal_number',
+ 'mark', 'description', 'get_first_base_find__discovery_date',
+ 'get_first_base_find__discovery_date_taq', 'get_first_base_find__batch',
+ 'is_complete', 'material_type', 'material_type_quality', 'object_type',
+ 'object_type_quality', 'find_number', 'min_number_of_individuals',
+ 'inscription', 'manufacturing_place', 'communicabilitie', 'comment',
+ 'dating_comment', 'length', 'width', 'height', 'diameter', 'thickness',
+ 'volume', 'weight', 'clutter_long_side', 'clutter_short_side',
+ 'clutter_height', 'dimensions_comment', 'get_first_base_find__x',
+ 'get_first_base_find__estimated_error_x', 'get_first_base_find__y',
+ 'get_first_base_find__estimated_error_y', 'get_first_base_find__z',
+ 'get_first_base_find__estimated_error_z',
+ 'get_first_base_find__spatial_reference_system',
+ 'get_first_base_find__topographic_localisation', 'checked_type',
+ 'check_date',
+ ]
+
+ HEADERS = BaseFindForm.HEADERS.copy()
+ get_first_base_find__excavation_id = forms.CharField(
+ label=_(u"Excavation ID"), required=False)
+
+ get_first_base_find__discovery_date = forms.DateField(
+ label=_(u"Discovery date (exact or TPQ)"), widget=DatePicker,
+ required=False)
+ get_first_base_find__discovery_date_taq = forms.DateField(
+ label=_(u"Discovery date (TAQ)"), widget=DatePicker, required=False)
+ get_first_base_find__batch = forms.ChoiceField(
+ label=_(u"Batch/object"), choices=[],
+ required=False)
+
+ HEADERS['get_first_base_find__x'] = FormHeader(_(u"Coordinates"))
get_first_base_find__x = forms.FloatField(label=_(u"X"), required=False)
get_first_base_find__estimated_error_x = \
forms.FloatField(label=_(u"Estimated error for X"), required=False)
@@ -231,22 +310,10 @@ class FindForm(CustomForm, ManageOldType):
required=False, max_length=120
)
- HEADERS['checked_type'] = FormHeader(_(u"Sheet"))
- checked_type = forms.ChoiceField(label=_(u"Check"), required=False)
- check_date = forms.DateField(
- initial=get_now, label=_(u"Check date"), widget=DatePicker)
-
- TYPES = [
- FieldType('material_type', models.MaterialType, is_multiple=True),
- FieldType('material_type_quality', models.MaterialTypeQualityType),
- FieldType('object_type', models.ObjectType, is_multiple=True),
- FieldType('object_type_quality', models.ObjectTypeQualityType),
- FieldType('communicabilitie', models.CommunicabilityType,
- is_multiple=True),
+ TYPES = BaseFindForm.TYPES + [
FieldType('get_first_base_find__batch', models.BatchType),
FieldType('get_first_base_find__spatial_reference_system',
SpatialReferenceSystem),
- FieldType('checked_type', models.CheckedType, is_multiple=True),
]
PROFILE_FILTER = {
'mapping': [
@@ -258,14 +325,8 @@ class FindForm(CustomForm, ManageOldType):
],
}
- def __init__(self, *args, **kwargs):
- context_record = kwargs.pop('context_record')
- super(FindForm, self).__init__(*args, **kwargs)
- if not context_record or \
- not context_record.operation.operation_type.judiciary:
- self.fields.pop('seal_number')
-
def clean(self):
+ self.cleaned_data = super(FindForm, self).clean()
taq = self.cleaned_data.get('get_first_base_find__discovery_date_taq',
None)
tpq = self.cleaned_data.get('get_first_base_find__discovery_date',
@@ -282,17 +343,6 @@ class FindForm(CustomForm, ManageOldType):
unicode(_(u"Discovery date: TAQ date must be older than TPQ "
u"date.")))
- clutter_long_side = self.cleaned_data.get('clutter_long_side', None)
- clutter_short_side = self.cleaned_data.get('clutter_short_side', None)
-
- if clutter_long_side and clutter_short_side and \
- clutter_short_side > clutter_long_side:
- raise forms.ValidationError(
- unicode(_(
- u"Clutter: short side cannot be bigger than the long side."
- ))
- )
-
if not get_current_profile().mapping:
return self.cleaned_data
x = self.cleaned_data.get('get_first_base_find__x', None)
@@ -320,6 +370,12 @@ class FindForm(CustomForm, ManageOldType):
return self.cleaned_data
+class SimpleFindForm(BaseFindForm):
+ def __init__(self, *args, **kwargs):
+ self.base_finds = kwargs.pop('base_finds')
+ super(SimpleFindForm, self).__init__(*args, **kwargs)
+
+
class ResultingFindForm(CustomForm, ManageOldType):
file_upload = True
form_label = _("Resulting find")