diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-12 18:42:36 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-12 18:42:36 +0100 | 
| commit | 6a8079dff5578f6f9101d57ff9567e079ec24e6f (patch) | |
| tree | 209ee729a9560358c46bed59bfbd3573fd30cad6 /archaeological_finds/forms.py | |
| parent | fc5579137bfa56ac7729ea82f28554a3250a0d34 (diff) | |
| download | Ishtar-6a8079dff5578f6f9101d57ff9567e079ec24e6f.tar.bz2 Ishtar-6a8079dff5578f6f9101d57ff9567e079ec24e6f.zip | |
Admin: add SRS. Find form: fix SRS field.
Diffstat (limited to 'archaeological_finds/forms.py')
| -rw-r--r-- | archaeological_finds/forms.py | 24 | 
1 files changed, 20 insertions, 4 deletions
| diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index d05b67470..11ecf8152 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -31,7 +31,8 @@ from django.forms.formsets import formset_factory  from django.utils.safestring import mark_safe  from django.utils.translation import ugettext_lazy as _ -from ishtar_common.models import valid_id, valid_ids, get_current_profile +from ishtar_common.models import valid_id, valid_ids, get_current_profile, \ +    SpatialReferenceSystem  from archaeological_operations.models import Period, ArchaeologicalSite, \      RelationType as OpeRelationType  from archaeological_context_records.models import DatingType, DatingQuality, \ @@ -128,7 +129,9 @@ class FindForm(ManageOldType, forms.Form):                           'object_type': models.ObjectType,                           'preservation_to_consider': models.PreservationType,                           'integritie': models.IntegrityType, -                         'remarkabilitie': models.RemarkabilityType} +                         'remarkabilitie': models.RemarkabilityType, +                         'get_first_base_find__spatial_reference_system': +                         SpatialReferenceSystem}      label = forms.CharField(          label=_(u"Free ID"),          validators=[validators.MaxLengthValidator(60)]) @@ -172,7 +175,8 @@ class FindForm(ManageOldType, forms.Form):      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) +        forms.ChoiceField(label=_(u"Spatial Reference System"), required=False, +                          choices=[])      length = FloatField(label=_(u"Length (cm)"), required=False)      width = FloatField(label=_(u"Width (cm)"), required=False)      height = FloatField(label=_(u"Height (cm)"), required=False) @@ -212,6 +216,13 @@ class FindForm(ManageOldType, forms.Form):                        'get_first_base_find__estimated_error_z',                        'get_first_base_find__spatial_reference_system',]:                  self.fields.pop(k) +        else: +            srs = 'get_first_base_find__spatial_reference_system' +            self.fields[srs].choices = \ +                SpatialReferenceSystem.get_types( +                    initial=self.init_data.get(srs)) +            self.fields[srs].help_text = \ +                SpatialReferenceSystem.get_help()          self.fields['checked'].choices = models.CHECK_CHOICES          self.fields['material_type'].help_text = models.MaterialType.get_help()          self.fields['conservatory_state'].choices = \ @@ -246,8 +257,13 @@ class FindForm(ManageOldType, forms.Form):              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' +        s = 'get_first_base_find__spatial_reference_system'          srs = self.cleaned_data.get(s, None) +        if srs: +            try: +                srs = SpatialReferenceSystem.objects.get(pk=srs) +            except SpatialReferenceSystem.DoesNotExist: +                srs = None          if x and y and not srs:              raise forms.ValidationError(                  _(u"You should at least provide X, Y and the spatial " | 
