diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-12-03 23:25:12 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-12-03 23:29:00 +0100 |
commit | c02bcd0e6c47c2cb3ce8b9b8927e408020e3a122 (patch) | |
tree | 758a052f8fd78bc2071bd4d6abb19a2c623876da /ishtar_common/wizards.py | |
parent | 0203ccf42cb3e8c79ea90a68f35818e4426b4d65 (diff) | |
download | Ishtar-c02bcd0e6c47c2cb3ce8b9b8927e408020e3a122.tar.bz2 Ishtar-c02bcd0e6c47c2cb3ce8b9b8927e408020e3a122.zip |
Adapt fields/forms/wizard for treatments
Diffstat (limited to 'ishtar_common/wizards.py')
-rw-r--r-- | ishtar_common/wizards.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index b9fba83b4..d207286ab 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -18,6 +18,7 @@ # See the file COPYING for details. import datetime +import logging # from functools import wraps from django.conf import settings @@ -38,6 +39,8 @@ from django.utils.datastructures import MultiValueDict as BaseMultiValueDict from django.utils.translation import ugettext_lazy as _ import models +logger = logging.getLogger(__name__) + class MultiValueDict(BaseMultiValueDict): def get(self, *args, **kwargs): @@ -167,6 +170,13 @@ class Wizard(NamedUrlWizardView): return super(Wizard, self).dispatch(request, *args, **kwargs) + def get_form_kwargs(self, step=None): + kwargs = super(Wizard, self).get_form_kwargs(step) + if hasattr(self.form_list[step], 'need_user_for_initialization') and\ + self.form_list[step].need_user_for_initialization: + kwargs['user'] = self.request.user + return kwargs + def get_prefix(self, *args, **kwargs): """As the class name can interfere when reused prefix with the url_name """ @@ -196,7 +206,7 @@ class Wizard(NamedUrlWizardView): self.request.session['CURRENT_ACTION'] = self.get_wizard_name() step = self.steps.first current_step = self.steps.current - dct = {'current_step': self.form_list[current_step], + dct = {'current_step_label': self.form_list[current_step].form_label, 'wizard_label': self.label, 'current_object': self.get_current_object(), 'is_search': current_step.startswith('selec-') @@ -211,7 +221,7 @@ class Wizard(NamedUrlWizardView): or (previous_steps and previous_steps[-1] == self.form_list[step]): break - previous_steps.append(self.form_list[step]) + previous_steps.append(self.form_list[step].form_label) previous_step_counter += 1 if previous_step_counter >= len(self.steps): break @@ -252,7 +262,7 @@ class Wizard(NamedUrlWizardView): if step == next_step: current_step_passed = True elif current_step_passed: - next_steps.append(self.form_list[next_step]) + next_steps.append(self.form_list[next_step].form_label) next_step = self.get_next_step(next_step) context.update({'next_steps': next_steps}) # not last step: validation @@ -485,9 +495,12 @@ class Wizard(NamedUrlWizardView): elif type(dct[k]) not in (list, tuple): dct[k] = [dct[k]] setattr(obj, k, dct[k]) + if hasattr(obj, 'pre_save'): + obj.pre_save() try: obj.full_clean() except ValidationError: + logger.warning(unicode(e)) return self.render(form_list[-1]) for dependant_item in other_objs: c_item = getattr(obj, dependant_item) @@ -550,9 +563,12 @@ class Wizard(NamedUrlWizardView): if k in dct: saved_args[k] = dct.pop(k) obj = self.get_saved_model()(**dct) + if hasattr(obj, 'pre_save'): + obj.pre_save() try: obj.full_clean() - except ValidationError: + except ValidationError as e: + logger.warning(unicode(e)) return self.render(form_list[-1]) obj.save(**saved_args) for k in adds: |