From 5106d06c318114cdc8766b260d78592a511860d8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 28 Oct 2013 13:44:04 +0100 Subject: Don't validate the form when clicking on previous step (refs #1462, refs #1463) If a field has been changed a confirmation dialog appear. --- archaeological_operations/wizards.py | 6 ++--- .../templates/ishtar/wizard/default_wizard.html | 18 +++++++++++++-- ishtar_common/wizards.py | 27 ++++++++++++---------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 48f7aeb65..f20999f18 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -179,12 +179,12 @@ class OperationWizard(Wizard): # add all parcel from available in the archaelogical file if not post_data.get('add_all_parcels'): - return super(Wizard, self).post(*args, **kwargs) + return super(OperationWizard, self).post(*args, **kwargs) general_form_key = 'general-' + self.url_name file_id = self.session_get_value(general_form_key, "associated_file") if not file_id: - return super(Wizard, self).post(*args, **kwargs) + return super(OperationWizard, self).post(*args, **kwargs) parcel_form_key = "parcels-" + self.url_name idx = -1 # remove non relevant deleted keys @@ -196,7 +196,7 @@ class OperationWizard(Wizard): post_data["%s-%d-parcel" % (parcel_form_key, idx)] = parcel_pk post_data[parcel_form_key+'-TOTAL_FORMS'] = idx + 1 request.POST = post_data - return super(Wizard, self).post(*args, **kwargs) + return super(OperationWizard, self).post(*args, **kwargs) class OperationModificationWizard(OperationWizard): modification = True diff --git a/ishtar_common/templates/ishtar/wizard/default_wizard.html b/ishtar_common/templates/ishtar/wizard/default_wizard.html index 28b9850d7..6b4bce709 100644 --- a/ishtar_common/templates/ishtar/wizard/default_wizard.html +++ b/ishtar_common/templates/ishtar/wizard/default_wizard.html @@ -9,11 +9,11 @@
{% csrf_token %} {% endblock %} @@ -44,4 +44,18 @@
{% endblock %} + {% endblock %} diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index f0302d70f..89f005a0a 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -534,18 +534,21 @@ class Wizard(NamedUrlWizardView): return super(Wizard, self).render_next_step(form, **kwargs) def post(self, *args, **kwargs): - """Convert numerical step number to step name""" - request = self.request - post_data = request.POST.copy() - if request.POST.has_key('form_prev_step'): - try: - step_number = int(request.POST['form_prev_step']) - post_data['wizard_goto_step'] = self.get_form_list().keys( - )[step_number] - except ValueError: - pass - request.POST = post_data - return super(Wizard, self).post(*args, **kwargs) + # manage previous (or next) step + form_prev_step = self.request.POST.get('form_prev_step', None) + if not form_prev_step: + return super(Wizard, self).post(*args, **kwargs) + try: + # convert numerical step number to step name + step_number = int(self.request.POST['form_prev_step']) + wizard_goto_step = self.get_form_list().keys()[step_number] + except (ValueError, IndexError): + return super(Wizard, self).post(*args, **kwargs) + self.storage.current_step = wizard_goto_step + form = self.get_form( + data=self.storage.get_step_data(self.steps.current), + files=self.storage.get_step_files(self.steps.current)) + return self.render(form) def session_has_key(self, form_key, key=None, multi=None): """Check if the session has value of a specific form and (if provided) -- cgit v1.2.3