summaryrefslogtreecommitdiff
path: root/archaeological_operations/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/forms.py')
-rw-r--r--archaeological_operations/forms.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 644114619..eaba1bca3 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -41,7 +41,7 @@ from ishtar_common.wizards import MultiValueDict
from archaeological_files.models import File
import models
-from widgets import ParcelWidget, SelectParcelWidget
+from widgets import ParcelWidget, SelectParcelWidget, OAWidget
from ishtar_common import widgets
from ishtar_common.forms import FinalForm, FormSet, get_now, \
@@ -458,7 +458,8 @@ class OperationSelect(TableSelect):
operation_code = forms.IntegerField(label=_(u"Numeric reference"))
if settings.COUNTRY == 'fr':
code_patriarche = forms.IntegerField(
- label="Numéro d'opération (OA Patriarche)")
+ widget=OAWidget,
+ label="Code PATRIARCHE")
towns = get_town_field()
parcel = ParcelField(label=_("Parcel (section/number/public domain)"))
if settings.ISHTAR_DPTS:
@@ -721,6 +722,7 @@ class OperationFormGeneral(forms.Form):
pk = forms.IntegerField(required=False, widget=forms.HiddenInput)
if settings.COUNTRY == 'fr':
code_patriarche = forms.IntegerField(label=u"Code PATRIARCHE",
+ widget=OAWidget,
required=False)
common_name = forms.CharField(label=_(u"Generic name"), required=False,
max_length=120, widget=forms.Textarea)
@@ -831,13 +833,24 @@ class OperationFormGeneral(forms.Form):
raise forms.ValidationError(
_(u"The excavation end date cannot be before the start "
u"date."))
+ # verify patriarche
+ code_p = self.cleaned_data.get('code_patriarche', None)
+
+ if code_p:
+ ops = models.Operation.objects.filter(code_patriarche=code_p)
+ if 'pk' in cleaned_data and cleaned_data['pk']:
+ ops = ops.exclude(pk=cleaned_data['pk'])
+ if ops.count():
+ msg = _(u"Ce code Patriarche a déjà été affecté à une "
+ u"autre opération")
+ raise forms.ValidationError(msg)
+ # manage unique operation ID
year = self.cleaned_data.get("year")
operation_code = cleaned_data.get("operation_code", None)
if not operation_code:
return self.cleaned_data
ops = models.Operation.objects.filter(year=year,
operation_code=operation_code)
- # manage unique operation ID
if 'pk' in cleaned_data and cleaned_data['pk']:
ops = ops.exclude(pk=cleaned_data['pk'])
if ops.count():
@@ -1150,7 +1163,8 @@ class OperationSourceSelect(SourceSelect):
label=_(u"Numeric reference"))
if settings.COUNTRY == 'fr':
operation__code_patriarche = forms.IntegerField(
- label="Numéro d'opération (OA Patriarche)")
+ widget=OAWidget,
+ label="Code PATRIARCHE")
operation__towns = get_town_field(label=_(u"Operation's town"))
operation__operation_type = forms.ChoiceField(label=_(u"Operation type"),
choices=[])
@@ -1181,7 +1195,8 @@ class AdministrativeActOpeSelect(TableSelect):
ref_sra = forms.CharField(label=u"Autre référence",
max_length=15)
operation__code_patriarche = forms.IntegerField(
- label="Numéro d'opération (OA Patriarche)")
+ widget=OAWidget,
+ label="Code PATRIARCHE")
act_type = forms.ChoiceField(label=_("Act type"), choices=[])
indexed = forms.NullBooleanField(label=_(u"Indexed?"))
operation__towns = get_town_field()