summaryrefslogtreecommitdiff
path: root/archaeological_context_records/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-12-03 17:14:13 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-12-03 17:14:41 +0100
commit07dc587a9441033d48ec17a28d2cfac5fb6b8fbe (patch)
treeaeef3e6775cadaff9b948aa142dfdac39d250859 /archaeological_context_records/forms.py
parentb2edacfd52f6fcfbceb44f7bc5eaa4d0779663ab (diff)
downloadIshtar-07dc587a9441033d48ec17a28d2cfac5fb6b8fbe.tar.bz2
Ishtar-07dc587a9441033d48ec17a28d2cfac5fb6b8fbe.zip
Sheet operation QA: add context record
Diffstat (limited to 'archaeological_context_records/forms.py')
-rw-r--r--archaeological_context_records/forms.py60
1 files changed, 52 insertions, 8 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index a4577df40..8bd3db9f5 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -28,7 +28,13 @@ from django.core import validators
from django.forms.formsets import formset_factory
from django.utils.translation import ugettext_lazy as _
-import models
+from ishtar_common.models import valid_id, IshtarSiteProfile, Town
+from archaeological_context_records import models
+
+from ishtar_common.forms import FinalForm, FormSet, \
+ reverse_lazy, get_form_selection, TableSelect, ManageOldType, CustomForm, \
+ FieldType, CustomFormSearch, IshtarForm
+from ishtar_common.forms_common import get_town_field
from archaeological_operations.forms import OperationSelect, ParcelField, \
RecordRelationsForm as OpeRecordRelationsForm, RecordRelationsFormSetBase
from archaeological_operations.models import Period, Parcel, Operation, \
@@ -36,11 +42,6 @@ from archaeological_operations.models import Period, Parcel, Operation, \
from archaeological_operations.widgets import OAWidget
from bootstrap_datepicker.widgets import DatePicker
from ishtar_common import widgets
-from ishtar_common.forms import FinalForm, FormSet, \
- reverse_lazy, get_form_selection, TableSelect, ManageOldType, CustomForm, \
- FieldType, CustomFormSearch
-from ishtar_common.forms_common import get_town_field
-from ishtar_common.models import valid_id, IshtarSiteProfile, Town
class OperationFormSelection(CustomForm, forms.Form):
@@ -154,6 +155,8 @@ class RecordFormGeneral(CustomForm, ManageOldType):
)
label = forms.CharField(label=_(u"ID"),
validators=[validators.MaxLengthValidator(200)])
+ unit = forms.ChoiceField(label=_(u"Context record type"), required=False,
+ choices=[])
description = forms.CharField(label=_(u"Description"),
widget=forms.Textarea, required=False)
comment = forms.CharField(label=_(u"General comment"),
@@ -167,8 +170,6 @@ class RecordFormGeneral(CustomForm, ManageOldType):
depth = forms.FloatField(label=_(u"Depth (m)"), required=False)
depth_of_appearance = forms.FloatField(
label=_(u"Depth of appearance (m)"), required=False)
- unit = forms.ChoiceField(label=_(u"Context record type"), required=False,
- choices=[])
opening_date = forms.DateField(label=_(u"Opening date"),
widget=DatePicker, required=False)
closing_date = forms.DateField(label=_(u"Closing date"),
@@ -374,3 +375,46 @@ class RecordDeletionForm(FinalForm):
confirm_msg = " "
confirm_end_msg = _(u"Would you like to delete this context record?")
+
+class QAOperationCR(IshtarForm):
+ town = forms.ChoiceField(label=_(u"Town"), choices=[])
+ archaeological_site = forms.ChoiceField(
+ label=" ", choices=[], required=False,
+ help_text=_(u"Only the items associated to the operation can be "
+ u"selected.")
+ )
+ label = forms.CharField(label=_(u"ID"),
+ validators=[validators.MaxLengthValidator(200)])
+ unit = forms.ChoiceField(label=_(u"Context record type"), required=False,
+ choices=[])
+
+ TYPES = [
+ FieldType('unit', models.Unit),
+ ]
+
+ def __init__(self, *args, **kwargs):
+ self.items = kwargs.pop('items')
+ super(QAOperationCR, self).__init__(*args, **kwargs)
+ site_label = IshtarSiteProfile.get_default_site_label()
+ self.fields['archaeological_site'].label = site_label
+ self.fields['archaeological_site'].choices = [('', '--')]
+
+ if not self.items:
+ return
+ operation = self.items[0]
+ 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()
+ ]
+
+ 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
+ )