summaryrefslogtreecommitdiff
path: root/archaeological_operations/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-08-23 11:07:45 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-08-23 11:07:45 +0200
commit7924c43af9044cfd40f36bd8a84378417223d95b (patch)
tree78197ea5c36baaff4fcc1a53580eb3d586630b39 /archaeological_operations/forms.py
parent54b87741a26a2bd805ed32200b082ca07ee0e27d (diff)
parent0bdaa7c90017b436b3baf026c9710a8d49c9420a (diff)
downloadIshtar-7924c43af9044cfd40f36bd8a84378417223d95b.tar.bz2
Ishtar-7924c43af9044cfd40f36bd8a84378417223d95b.zip
Merge branch 'master' into v0.9
Conflicts: ishtar_common/migrations/0053_auto__add_field_ishtarsiteprofile_currency.py
Diffstat (limited to 'archaeological_operations/forms.py')
-rw-r--r--archaeological_operations/forms.py96
1 files changed, 71 insertions, 25 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index b61285177..67cc8892d 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -41,11 +41,11 @@ 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, \
- reverse_lazy, get_form_selection, TableSelect
+ reverse_lazy, get_form_selection, TableSelect, get_data_from_formset
from ishtar_common.forms_common import TownFormSet, SourceForm, SourceSelect, \
get_town_field
@@ -76,6 +76,22 @@ class ParcelForm(forms.Form):
parcel_number = forms.CharField(
label=_(u"Parcel number"), required=False,
validators=[validators.MaxLengthValidator(6)])
+ public_domain = forms.BooleanField(label=_(u"Public domain"),
+ initial=False, required=False)
+
+ def count_valid_fields(self, data):
+ if not data:
+ return 0
+ data = get_data_from_formset(data)
+ nb = len(data)
+ # remove last non relevant fields
+ for idx, vals in enumerate(reversed(data[:])):
+ if 'public_domain' in vals:
+ break
+ if 'section' in vals and 'parcel_number' in vals:
+ break
+ nb -= 1
+ return nb
def __init__(self, *args, **kwargs):
towns = None
@@ -99,13 +115,12 @@ class ParcelForm(forms.Form):
if not self.cleaned_data or (DELETION_FIELD_NAME in self.cleaned_data
and self.cleaned_data[DELETION_FIELD_NAME]):
return
- if not self.cleaned_data.get('parcel_number') and \
- self.cleaned_data.get('section') != 'DP':
+ if (not self.cleaned_data.get('parcel_number') or
+ not self.cleaned_data.get('section')) and \
+ not self.cleaned_data.get('public_domain'):
return {}
- for key in ('town', 'section'):
- if key not in self.cleaned_data or not self.cleaned_data[key]:
- raise forms.ValidationError(_(u"Town section and parcel number"
- u" fields are required."))
+ if not self.cleaned_data.get('town'):
+ raise forms.ValidationError(_(u"Town section is required."))
return self.cleaned_data
@classmethod
@@ -141,7 +156,9 @@ class ParcelForm(forms.Form):
else:
c_number = 0
values = [town, data.get('year') or '', data.get('section') or '',
- c_number, data.get('parcel_number') or '']
+ c_number, str(data.get('parcel_number') or '')
+ + str(u"Public domain") if data.get('public_domain')
+ else u""]
if data.get('DELETE'):
deleted.append(values)
else:
@@ -247,15 +264,17 @@ class ParcelFormSet(FormSet):
parcel.parcel_number]
continue
if number not in ordering_keys:
- ordering_keys[number] = ['', '', '', '']
- if field == 'town':
+ ordering_keys[number] = ['', '', '', '', '']
+ if field == 'public_domain':
ordering_keys[number][0] = value
- elif field == 'year':
+ elif field == 'town':
ordering_keys[number][1] = value
- elif field == 'section':
+ elif field == 'year':
ordering_keys[number][2] = value
- elif field == 'parcel_number':
+ elif field == 'section':
ordering_keys[number][3] = value
+ elif field == 'parcel_number':
+ ordering_keys[number][4] = value
reverse_ordering_keys = {}
for number in ordering_keys:
@@ -271,7 +290,7 @@ class ParcelFormSet(FormSet):
return new_values
def _parcel_sorting(self, key):
- town, year, section, parcel = key
+ public_domain, town, year, section, parcel = key
# deal with parcel_number such as '34p' and convert to int
parcel_number = ''
for p in parcel:
@@ -283,7 +302,12 @@ class ParcelFormSet(FormSet):
parcel_number = 0
else:
parcel_number = int(parcel_number)
- return (town, year, section, parcel_number)
+ # empty must be at the end
+ if not year and not section and not parcel_number \
+ and not public_domain:
+ Z = 'ZZZZZZZZZZZZZ'
+ return (Z, Z, Z, Z, Z)
+ return (town, year, section, parcel_number, public_domain)
def as_table(self):
# add dynamic widget
@@ -434,9 +458,10 @@ 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)"))
+ parcel = ParcelField(label=_("Parcel (section/number/public domain)"))
if settings.ISHTAR_DPTS:
towns__numero_insee__startswith = forms.ChoiceField(
label=_(u"Department"), choices=[])
@@ -536,6 +561,7 @@ class OperationSelect(TableSelect):
ids.pop(ids.index('parcel'))
ids.append('parcel_0')
ids.append('parcel_1')
+ ids.append('parcel_2')
ids.pop(ids.index('relation_types'))
for idx, c in enumerate(self.fields['relation_types'].choices):
ids.append('relation_types_{}'.format(idx))
@@ -696,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)
@@ -705,6 +732,9 @@ class OperationFormGeneral(forms.Form):
initial=lambda: datetime.datetime.now().year,
validators=[validators.MinValueValidator(1900),
validators.MaxValueValidator(2100)])
+ old_code = forms.CharField(
+ label=_(u"Old code"), required=False,
+ validators=[validators.MaxLengthValidator(200)])
scientist = forms.IntegerField(
label=_("Head scientist"),
widget=widgets.JQueryAutoComplete(
@@ -751,9 +781,6 @@ class OperationFormGeneral(forms.Form):
report_processing = forms.ChoiceField(label=_(u"Report processing"),
choices=[], required=False)
if settings.COUNTRY == 'fr':
- code_dracar = forms.CharField(
- label=u"Code DRACAR", required=False,
- validators=[validators.MaxLengthValidator(10)])
cira_date = forms.DateField(label=u"Date avis CIRA", required=False,
widget=widgets.JQueryDate)
negative_result = forms.NullBooleanField(
@@ -806,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():
@@ -1120,10 +1158,16 @@ SourceOperationFormSelection = get_form_selection(
class OperationSourceSelect(SourceSelect):
+ operation__year = forms.IntegerField(label=_(u"Operation's year"))
+ operation__operation_code = forms.IntegerField(
+ label=_(u"Numeric reference"))
+ if settings.COUNTRY == 'fr':
+ operation__code_patriarche = forms.IntegerField(
+ 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=[])
- operation__year = forms.IntegerField(label=_(u"Operation's year"))
def __init__(self, *args, **kwargs):
super(OperationSourceSelect, self).__init__(*args, **kwargs)
@@ -1151,11 +1195,12 @@ 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()
- parcel = ParcelField(label=_("Parcel (section/number)"))
+ parcel = ParcelField(label=_("Parcel (section/number/public domain)"))
if settings.ISHTAR_DPTS:
operation__towns__numero_insee__startswith = forms.ChoiceField(
label=_(u"Department"), choices=[])
@@ -1191,6 +1236,7 @@ class AdministrativeActOpeSelect(TableSelect):
ids.pop(ids.index('parcel'))
ids.append('parcel_0')
ids.append('parcel_1')
+ ids.append('parcel_2')
return ids