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.py46
1 files changed, 44 insertions, 2 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 9441e6899..d05b67470 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -43,6 +43,7 @@ from ishtar_common.forms import FormSet, FloatField, \
ManageOldType
from ishtar_common.forms_common import get_town_field, SourceSelect
+from ishtar_common.utils import convert_coordinates_to_point
from ishtar_common import widgets
from archaeological_operations.widgets import OAWidget
@@ -157,10 +158,21 @@ class FindForm(ManageOldType, forms.Form):
remarkabilitie = forms.MultipleChoiceField(
label=_(u"Remarkability"), choices=[],
widget=widgets.CheckboxSelectMultiple, required=False)
- topographic_reference_point = forms.CharField(
+ get_first_base_find__topographic_localisation = forms.CharField(
label=_(u"Point of topographic reference"),
- required=False, max_length=20
+ required=False, max_length=120
)
+ 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)
+ get_first_base_find__y = forms.FloatField(label=_(u"Y"), required=False)
+ get_first_base_find__estimated_error_y = \
+ forms.FloatField(label=_(u"Estimated error for Y"), required=False)
+ get_first_base_find__z = forms.FloatField(label=_(u"Z"), required=False)
+ get_first_base_find__estimated_error_z = \
+ forms.FloatField(label=_(u"Estimated error for Z"), required=False)
+ get_first_base_find__spatial_reference_system = \
+ forms.FloatField(label=_(u"Spatial Reference System"), required=False)
length = FloatField(label=_(u"Length (cm)"), required=False)
width = FloatField(label=_(u"Width (cm)"), required=False)
height = FloatField(label=_(u"Height (cm)"), required=False)
@@ -192,6 +204,14 @@ class FindForm(ManageOldType, forms.Form):
def __init__(self, *args, **kwargs):
super(FindForm, self).__init__(*args, **kwargs)
+ if not get_current_profile().mapping:
+ for k in ['get_first_base_find__x', 'get_first_base_find__y',
+ 'get_first_base_find__z',
+ 'get_first_base_find__estimated_error_x',
+ 'get_first_base_find__estimated_error_y',
+ 'get_first_base_find__estimated_error_z',
+ 'get_first_base_find__spatial_reference_system',]:
+ self.fields.pop(k)
self.fields['checked'].choices = models.CHECK_CHOICES
self.fields['material_type'].help_text = models.MaterialType.get_help()
self.fields['conservatory_state'].choices = \
@@ -221,6 +241,28 @@ class FindForm(ManageOldType, forms.Form):
unicode(self.fields['estimated_value'].label),
get_current_profile().currency)
+ def clean(self):
+ if not get_current_profile().mapping:
+ return self.cleaned_data
+ x = self.cleaned_data.get('get_first_base_find__x', None)
+ y = self.cleaned_data.get('get_first_base_find__y', None)
+ s = 'get_first_base_find__get_first_base_find__spatial_reference_system'
+ srs = self.cleaned_data.get(s, None)
+ if x and y and not srs:
+ raise forms.ValidationError(
+ _(u"You should at least provide X, Y and the spatial "
+ u"reference system used."))
+ if x and y and srs:
+ try:
+ convert_coordinates_to_point(
+ x, y, self.cleaned_data.get('get_first_base_find__z', None),
+ srs.srid)
+ except forms.ValidationError as e:
+ raise forms.ValidationError(
+ unicode(_(u"Coordinates are not relevant for the spatial "
+ u"reference system used: {}.")).format(e))
+ return self.cleaned_data
+
class DateForm(ManageOldType, forms.Form):
form_label = _("Dating")