From 5a12bcce1cfad8fcf93f902bc9e4c82c4a53ee14 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 12 Feb 2015 23:34:01 +0100 Subject: Add a new reset wizard action available from main templates (refs #2282) --- ishtar_common/templates/ishtar/wizard/default_wizard.html | 2 ++ ishtar_common/urls.py | 1 + ishtar_common/views.py | 14 ++++++++++++++ ishtar_common/wizards.py | 7 +++++++ 4 files changed, 24 insertions(+) (limited to 'ishtar_common') diff --git a/ishtar_common/templates/ishtar/wizard/default_wizard.html b/ishtar_common/templates/ishtar/wizard/default_wizard.html index 3f2f3943e..2eb62457b 100644 --- a/ishtar_common/templates/ishtar/wizard/default_wizard.html +++ b/ishtar_common/templates/ishtar/wizard/default_wizard.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load i18n range table_form %} +{% load url from future %} {% block extra_head %} {{form.media}} {% endblock %} @@ -43,6 +44,7 @@
{% if next_steps %}{% endif %} +
diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 0c4059eeb..10a397fe0 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -123,6 +123,7 @@ urlpatterns += patterns('ishtar_common.views', url(r'person_merge/(?:(?P\d+)/)?$', 'person_merge', name='person_merge'), url(r'organization_merge/(?:(?P\d+)/)?$', 'organization_merge', name='organization_merge'), + url(r'reset/$', 'reset_wizards', name='reset_wizards'), url(r'(?P' + actions + r')/$', 'action', name='action'), ) diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 1885493b1..7b2fffcef 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -832,6 +832,20 @@ def dashboard_main_detail(request, item_name): return render_to_response('ishtar/dashboards/dashboard_main_detail.html', dct, context_instance=RequestContext(request)) +def reset_wizards(request): + # dynamicaly execute each reset_wizards of each ishtar app + for app in settings.INSTALLED_APPS: + if app == 'ishtar_common': + # no need for infinite recursion + continue + try: + module = __import__(app) + except ImportError: + continue + if hasattr(module, 'views') and hasattr(module.views, 'reset_wizards'): + module.views.reset_wizards(request) + return redirect(reverse('start')) + ITEM_PER_PAGE = 20 def merge_action(model, form, key): def merge(request, page=1): diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 2ad3635d7..1e515d13e 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -619,6 +619,13 @@ class Wizard(NamedUrlWizardView): form_key + '-0-' + key #only check if the first field is available return key in request.session[storage.prefix]['step_data'][form_key] + @classmethod + def session_reset(cls, request, url_name): + prefix = url_name + normalize_name(cls.__name__) + storage = get_storage(cls.storage_name, prefix, request, + getattr(cls, 'file_storage', None)) + storage.reset() + @classmethod def session_set_value(cls, request, form_key, key, value, reset=False): prefix = form_key.split('-')[1] + normalize_name(cls.__name__) -- cgit v1.2.3