diff options
Diffstat (limited to 'archaeological_operations')
| -rw-r--r-- | archaeological_operations/forms.py | 12 | ||||
| -rw-r--r-- | archaeological_operations/wizards.py | 36 | 
2 files changed, 40 insertions, 8 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 741dfb2b7..72834d8f0 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -59,13 +59,13 @@ class ParcelForm(forms.Form):      associated_models = {'parcel':models.Parcel, 'town':models.Town}      town = forms.ChoiceField(label=_("Town"), choices=(), required=False,                               validators=[valid_id(models.Town)]) +    year = forms.IntegerField(label=_("Year"), required=False, +                           validators=[validators.MinValueValidator(1900), +                                       validators.MaxValueValidator(2100)])      section = forms.CharField(label=_(u"Section"), required=False,                               validators=[validators.MaxLengthValidator(4)])      parcel_number = forms.CharField(label=_(u"Parcel number"), required=False,                               validators=[validators.MaxLengthValidator(6)]) -    year = forms.IntegerField(label=_("Year"), required=False, -                           validators=[validators.MinValueValidator(1900), -                                       validators.MaxValueValidator(2100)])      def __init__(self, *args, **kwargs):          towns = None          if 'data' in kwargs and 'TOWNS' in kwargs['data']: @@ -85,9 +85,11 @@ class ParcelForm(forms.Form):          """Check required fields"""          if any(self.errors):              return -        if not self.cleaned_data or DELETION_FIELD_NAME in self.cleaned_data \ -           and self.cleaned_data[DELETION_FIELD_NAME]: +        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'): +            return {}          for key in ('town', 'parcel_number', 'section'):              if not key in self.cleaned_data or not self.cleaned_data[key]:                  raise forms.ValidationError(_(u"Town section and parcel number " diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 2b13e3353..4205144e6 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -27,16 +27,19 @@ from django.utils.translation import ugettext_lazy as _  from ishtar_common.wizards import Wizard, ClosingWizard, DeletionWizard, \                                    SourceWizard  import models +from forms import ParcelForm  class OperationWizard(Wizard):      model = models.Operation      object_parcel_type = 'operation' +    parcel_step_key = 'parcelsgeneral-'      def get_template_names(self):          templates = super(OperationWizard, self).get_template_names()          current_step = self.steps.current          if current_step.startswith('towns-'): -            templates = ['ishtar/wizard/towns_wizard.html'] + templates +            #templates = ['ishtar/wizard/towns_wizard.html'] + templates +            pass          if current_step.startswith('parcels-') or \             current_step.startswith('parcelsgeneral-') :              templates = ['ishtar/wizard/parcels_wizard.html'] + templates @@ -124,7 +127,7 @@ class OperationWizard(Wizard):          Show a specific warning if no archaelogical file is provided          """          datas = super(OperationWizard, self).get_formated_datas(forms) -        # if the general town form is used the advertissement is pertinent +        # if the general town form is used the advertissement is relevant          has_no_af = [form.prefix for form in forms                    if form.prefix == 'townsgeneral-operation'] and True          if has_no_af: @@ -133,6 +136,33 @@ class OperationWizard(Wizard):                  + datas          return datas +    def get_form_initial(self, step, data=None): +        initial = super(OperationWizard, self).get_form_initial(step) +        self.form_initialized = False +        if not step.startswith(self.parcel_step_key): +            return initial +        if initial: +            default = initial[-1].copy() +            if 'parcel_number' in default: +                default.pop('parcel_number') +            initial.append(default) +            # necessary to get the appropriate form number +            self.form_initialized = True +        elif data: +            numbers, keys = set(), set() +            for k in data: +                items = k.split('-') +                try: +                    numbers.add(int(items[-2])) +                except (ValueError, IndexError): +                    continue +                keys.add(items[-1]) +            if max(numbers) - 1: +                initial = [dict([(k, data[step+'-'+unicode(max(numbers)-1)+'-'+k]) +                                           for k in keys if k != 'parcel_number'])] +            self.form_initialized = True +        return initial +  class OperationModificationWizard(OperationWizard):      modification = True @@ -148,7 +178,7 @@ class OperationDeletionWizard(DeletionWizard):  class OperationSourceWizard(SourceWizard):      model = models.OperationSource -    def get_form_initial(self, step): +    def get_form_initial(self, step, data=None):          initial = super(OperationSourceWizard, self).get_form_initial(step)          # put default index and operation_id field in the main source form          general_form_key = 'selec-' + self.url_name  | 
