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 | 7e060ac1a352ec2c290732988d8e3bacbb204c86 (patch) | |
tree | 758a052f8fd78bc2071bd4d6abb19a2c623876da /ishtar_common | |
parent | e67702f06e1f9866c44df3a7e45f2739d43513f4 (diff) | |
download | Ishtar-7e060ac1a352ec2c290732988d8e3bacbb204c86.tar.bz2 Ishtar-7e060ac1a352ec2c290732988d8e3bacbb204c86.zip |
Adapt fields/forms/wizard for treatments
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 1 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/default_wizard.html | 6 | ||||
-rw-r--r-- | ishtar_common/views.py | 5 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 24 |
4 files changed, 28 insertions, 8 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 5b822c7dd..ebb9c9588 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2639,7 +2639,6 @@ class IshtarUser(User): surname = user.first_name or default name = user.last_name or default email = user.email - person_type = None if user.is_superuser: ADMINISTRATOR, created = PersonType.objects.get_or_create( txt_idx='administrator') diff --git a/ishtar_common/templates/ishtar/wizard/default_wizard.html b/ishtar_common/templates/ishtar/wizard/default_wizard.html index c52d71536..d886396b3 100644 --- a/ishtar_common/templates/ishtar/wizard/default_wizard.html +++ b/ishtar_common/templates/ishtar/wizard/default_wizard.html @@ -10,11 +10,11 @@ <form action="." method="post">{% csrf_token %} <ul id='form_path'> {% for step in previous_steps %} - <li><button class='change_step' name="form_prev_step" value="{{forloop.counter0}}">{{step.form_label}}</button></li> + <li><button class='change_step' name="form_prev_step" value="{{forloop.counter0}}">{{step}}</button></li> {% endfor %} - <li class='current'><a href='#'>{{current_step.form_label}}</a></li> + <li class='current'><a href='#'>{{current_step_label}}</a></li> {% for step in next_steps %} - <li><button class='change_step' name="form_prev_step" value="{{forloop.counter|add:previous_step_counter}}">{{step.form_label}}</button></li> + <li><button class='change_step' name="form_prev_step" value="{{forloop.counter|add:previous_step_counter}}">{{step}}</button></li> {% endfor %} </ul> </form> diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 4a7c7e2e8..16201b1a2 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -914,6 +914,11 @@ def get_item(model, func_name, default_name, extra_request_keys=[], for k in keys: if k in model.EXTRA_REQUEST_KEYS: k = model.EXTRA_REQUEST_KEYS[k] + if type(k) in (list, tuple): + k = k[0] + for filtr in ('__icontains', '__contains'): + if k.endswith(filtr): + k = k[:len(k) - len(filtr)] vals = [item] # foreign key may be divided by "." or "__" splitted_k = [] 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: |