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.py49
1 files changed, 26 insertions, 23 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 76d7055d9..2754f2d1a 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -103,6 +103,8 @@ class ParcelForm(forms.Form):
return self.cleaned_data
class ParcelSelectionForm(forms.Form):
+ _town = forms.ChoiceField(label=_("Town"), choices=(), required=False,
+ validators=[valid_id(models.Town)])
_parcel_selection = forms.CharField(label=_(u"Full text input"),
widget=SelectParcelWidget(attrs={'class':'parcel-select'}),
max_length=100, help_text=_(u"example: \"2013: XD:1 to "\
@@ -118,6 +120,13 @@ class ParcelFormSet(FormSet):
if self.forms[0].__class__.__name__ == 'ParcelForm':
self.selection_form = ParcelSelectionForm()
self.extra_form = self.selection_form
+ # copy town choices
+ town_choices = self.forms[0].fields['town'].choices[:]
+ if town_choices and not town_choices[0][0]:
+ # remove empty
+ town_choices = town_choices[1:]
+ if town_choices:
+ self.selection_form.fields['_town'].choices = town_choices
def as_table(self):
# add dynamic widget
@@ -142,25 +151,14 @@ class ParcelFormSet(FormSet):
def clean(self):
# manage parcel selection
- last_town, parcels = None, []
- if hasattr(self, 'cleaned_data') and self.cleaned_data:
- for parcel in reversed(self.cleaned_data):
- if parcel.get('town'):
- last_town = parcel.get('town')
- break
- if not last_town and 'town' in self.forms[0].fields.keys():
- towns = self.forms[0].fields['town'].choices
- if towns:
- towns.pop(0) # remove first empty
- if towns:
- last_town = towns[0][0]
+ selected_town, parcels = None, []
if self.data.get('_parcel_selection'):
parcels = parse_parcels(self.data['_parcel_selection'])
- if last_town:
- for idx, parcel in enumerate(parcels):
- parcel['town'] = last_town
- parcel['DELETE'] = False
- parcels[idx] = parcel
+ selected_town = self.data.get('_town')
+ for idx, parcel in enumerate(parcels):
+ parcel['town'] = selected_town
+ parcel['DELETE'] = False
+ parcels[idx] = parcel
c_max = self.total_form_count()
# pop the last extra form
extra_form = self.forms.pop()
@@ -188,6 +186,8 @@ ParcelFormSet = formset_factory(ParcelForm, can_delete=True,
ParcelFormSet.form_label = _(u"Parcels")
class OperationSelect(TableSelect):
+ year = forms.IntegerField(label=_("Year"))
+ operation_code = forms.IntegerField(label=_(u"Numeric reference"))
common_name = forms.CharField(label=_(u"Name (full text search)"),
max_length=30)
if settings.COUNTRY == 'fr':
@@ -203,7 +203,6 @@ class OperationSelect(TableSelect):
associated_model=Person), label=_(u"In charge"))
remains = forms.ChoiceField(label=_(u"Remains"), choices=[])
periods = forms.ChoiceField(label=_(u"Periods"), choices=[])
- year = forms.IntegerField(label=_("Year"))
start_before = forms.DateField(label=_(u"Started before"),
widget=widgets.JQueryDate)
start_after = forms.DateField(label=_(u"Started after"),
@@ -591,8 +590,13 @@ OperationSourceFormSelection = get_form_selection(
################################################
class AdministrativeActOpeSelect(TableSelect):
- operation__towns = get_town_field()
+ year = forms.IntegerField(label=_("Year"))
+ index = forms.IntegerField(label=_("Index"))
+ if settings.COUNTRY == 'fr':
+ ref_sra = forms.CharField(label=u"Référence SRA",
+ max_length=15)
act_type = forms.ChoiceField(label=_("Act type"), choices=[])
+ operation__towns = get_town_field()
def __init__(self, *args, **kwargs):
super(AdministrativeActOpeSelect, self).__init__(*args, **kwargs)
@@ -684,13 +688,12 @@ class GenerateDocForm(forms.Form):
self.fields['doc_generation'].choices = [('', u'-'*9)] + \
[(choice.pk , unicode(choice)) for choice in choices]
-class AdministrativeActRegisterSelect(TableSelect):
- signature_date__year = forms.IntegerField(label=_(u"Year"))
- act_type = forms.ChoiceField(label=_("Act type"), choices=[])
+class AdministrativeActRegisterSelect(AdministrativeActOpeSelect):
def __init__(self, *args, **kwargs):
super(AdministrativeActRegisterSelect, self).__init__(*args, **kwargs)
- self.fields['act_type'].choices = models.ActType.get_types()
+ self.fields['act_type'].choices = models.ActType.get_types(
+ dct={'indexed':True})
self.fields['act_type'].help_text = models.ActType.get_help()
class AdministrativeActRegisterFormSelection(forms.Form):