summaryrefslogtreecommitdiff
path: root/archaeological_context_records/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/forms.py')
-rw-r--r--archaeological_context_records/forms.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index a14fb02d8..28eb123a1 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -416,6 +416,7 @@ class QAOperationCR(IshtarForm):
)
label = forms.CharField(label=_(u"ID"),
validators=[validators.MaxLengthValidator(200)])
+ parcel = forms.ChoiceField(label=_(u"Parcel"), choices=[], required=False)
unit = forms.ChoiceField(label=_(u"Context record type"), required=False,
choices=[])
@@ -426,26 +427,42 @@ class QAOperationCR(IshtarForm):
def __init__(self, *args, **kwargs):
self.items = kwargs.pop('items')
super(QAOperationCR, self).__init__(*args, **kwargs)
- site_label = IshtarSiteProfile.get_default_site_label()
+ self.profil = IshtarSiteProfile.get_current_profile()
+ site_label = self.profil.get_site_label()
self.fields['archaeological_site'].label = site_label
self.fields['archaeological_site'].choices = [('', '--')]
+ if self.profil.parcel_mandatory:
+ self.fields['parcel'].required = True
+ self.fields.pop('town')
if not self.items:
return
operation = self.items[0]
- self.fields['town'].choices = [(t.pk, unicode(t))
- for t in operation.towns.all()]
+ if not self.profil.parcel_mandatory:
+ self.fields['town'].choices = [(t.pk, unicode(t))
+ for t in operation.towns.all()]
self.fields['archaeological_site'].choices += [
(site.pk, unicode(site))
for site in operation.archaeological_sites.all()
]
+ self.fields['parcel'].choices += [('', '--')] + [
+ (str(parcel.pk), u"{} - {}".format(parcel.short_label, parcel.town))
+ for parcel in operation.parcels.all()
+ ]
def save(self, items):
operation = items[0]
- cr = models.ContextRecord.objects.create(
- town_id=self.cleaned_data['town'], operation=operation,
- archaeological_site_id=
- self.cleaned_data['archaeological_site'] or None,
- label=self.cleaned_data['label'],
- unit_id=self.cleaned_data['unit'] or None
- )
+ data = {
+ "operation": operation,
+ "archaeological_site_id":
+ self.cleaned_data['archaeological_site'] or None,
+ "label": self.cleaned_data['label'],
+ "unit_id": self.cleaned_data['unit'] or None
+ }
+ if self.profil.parcel_mandatory:
+ data["parcel_id"] = self.cleaned_data['parcel']
+ else:
+ if self.cleaned_data.get('parcel', None):
+ data["parcel_id"] = self.cleaned_data['parcel']
+ data["town_id"] = self.cleaned_data['town']
+ models.ContextRecord.objects.create(**data)