diff options
Diffstat (limited to 'ishtar/ishtar_base/forms.py')
| -rw-r--r-- | ishtar/ishtar_base/forms.py | 38 | 
1 files changed, 32 insertions, 6 deletions
| diff --git a/ishtar/ishtar_base/forms.py b/ishtar/ishtar_base/forms.py index e4f52b1cd..287a181f4 100644 --- a/ishtar/ishtar_base/forms.py +++ b/ishtar/ishtar_base/forms.py @@ -105,6 +105,7 @@ class SearchWizard(NamedUrlSessionFormWizard):  class Wizard(NamedUrlSessionFormWizard):      model = None +    modification = None # True when the wizard modify an item      def get_wizard_name(self):          """ @@ -122,7 +123,7 @@ class Wizard(NamedUrlSessionFormWizard):      def get_template_context(self, request, storage, form=None):          """ -        Add previous and current steps to manage the wizard path +        Add previous, next and current steps to manage the wizard path          """          context = super(Wizard, self).get_template_context(request, storage,                                                             form) @@ -132,13 +133,38 @@ class Wizard(NamedUrlSessionFormWizard):          context.update({'current_step':self.form_list[current_step]})          if step == current_step:              return context -        previous_steps = [] +        previous_steps, next_steps, previous_step_counter = [], [], 0          while step:              if step == current_step:                  break              previous_steps.append(self.form_list[step])              step = self.get_next_step(request, storage, step) -        context.update({'previous_steps':previous_steps}) +            previous_step_counter += 1 +        context.update({'previous_steps':previous_steps, +                        'previous_step_counter':previous_step_counter}) +        # if modification: show the next steps +        next_step = step +        if self.modification: +            while next_step: +                # check if the form is initialized otherwise initialize it +                if not storage.get_step_data(next_step): +                    values = self.get_form_initial(request, storage, next_step) +                    prefixed_values = {} +                    if not isinstance(values, list): +                        for key in values: +                            form_key = next_step + '-' + key +                            prefixed_values[form_key] = values[key] +                    else: +                        for formset_idx, v in enumerate(values): +                            prefix = u"-%d-" % formset_idx +                            for key in v: +                                form_key = next_step + prefix + key +                                prefixed_values[form_key] = v[key] +                    storage.set_step_data(next_step, prefixed_values) +                if step != next_step: # if not current step +                    next_steps.append(self.form_list[next_step]) +                next_step = self.get_next_step(request, storage, next_step) +        context.update({'next_steps':next_steps})          # not last step: validation          if step != self.get_last_step(request, storage):              return context @@ -582,12 +608,12 @@ class Wizard(NamedUrlSessionFormWizard):                  return initial          return super(Wizard, self).get_form_initial(request, storage, step) -    def get_instanced_init(self, obj, request, storage, step): +    def get_instanced_init(self, obj, request, storage, step=None):          """          Get initial data from an init          """ -        current_step = storage.get_current_step() or self.get_first_step( -                                                            request, storage) +        current_step = step or  storage.get_current_step() \ +                       or self.get_first_step(request, storage)          c_form = self.form_list[current_step]          # make the current object the default item for the session          obj_name = obj.__class__.__name__.lower() | 
