diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-04-05 00:33:07 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-04-05 00:33:07 +0200 | 
| commit | e51684c2adb656d3ef14e40e649e280a6c0bf1b8 (patch) | |
| tree | a2c624b1ce76c6d57a8a156766e4863710d8ae19 /archaeological_operations/wizards.py | |
| parent | c5e94062adefdd8cb0aeb730830921d5d546a86b (diff) | |
| download | Ishtar-e51684c2adb656d3ef14e40e649e280a6c0bf1b8.tar.bz2 Ishtar-e51684c2adb656d3ef14e40e649e280a6c0bf1b8.zip | |
UI improvment for parcels management (refs #151)
Diffstat (limited to 'archaeological_operations/wizards.py')
| -rw-r--r-- | archaeological_operations/wizards.py | 36 | 
1 files changed, 33 insertions, 3 deletions
| 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 | 
