summaryrefslogtreecommitdiff
path: root/ishtar_common/wizards.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/wizards.py')
-rw-r--r--ishtar_common/wizards.py38
1 files changed, 26 insertions, 12 deletions
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 874b68eae..8d787d733 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -51,10 +51,16 @@ class MultiValueDict(BaseMultiValueDict):
v = v()
if type(v) in (list, tuple) and len(v) > 1:
v = ",".join(v)
- else:
+ elif type(v) not in (int, unicode):
v = super(MultiValueDict, self).get(*args, **kwargs)
return v
+ def getlist(self, *args, **kwargs):
+ lst = super(MultiValueDict, self).getlist(*args, **kwargs)
+ if type(lst) not in (tuple, list):
+ lst = [lst]
+ return lst
+
def check_rights(rights=[], redirect_url='/'):
"""
@@ -132,6 +138,7 @@ class Wizard(NamedUrlWizardView):
current_object_key = 'pk'
ignore_init_steps = []
file_storage = default_storage
+ main_item_select_keys = ('selec-',)
saved_args = {} # argument to pass on object save
@@ -217,8 +224,9 @@ class Wizard(NamedUrlWizardView):
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-')
- if current_step else False
+ 'is_search': bool(
+ [k for k in self.main_item_select_keys
+ if current_step.startswith(k)]) if current_step else False
}
context.update(dct)
if step == current_step:
@@ -406,6 +414,8 @@ class Wizard(NamedUrlWizardView):
for form in form_list:
if not form.is_valid():
return self.render(form)
+ if hasattr(form, 'readonly') and form.readonly:
+ continue
base_form = hasattr(form, 'forms') and form.forms[0] or form
associated_models = hasattr(base_form, 'associated_models') and \
base_form.associated_models or {}
@@ -815,7 +825,7 @@ class Wizard(NamedUrlWizardView):
# get a form key
frm = form.form
if callable(frm):
- frm = frm()
+ frm = frm(self.get_form_kwargs(step))
total_field = 0
if hasattr(frm, 'count_valid_fields'):
@@ -1004,20 +1014,24 @@ class Wizard(NamedUrlWizardView):
def get_current_object(self):
"""Get the current object for an instancied wizard"""
current_obj = None
- main_form_key = 'selec-' + self.url_name
- try:
- idx = self.session_get_value(main_form_key, self.current_object_key)
- idx = int(idx)
- current_obj = self.model.objects.get(pk=idx)
- except(TypeError, ValueError, ObjectDoesNotExist):
- pass
+ for key in self.main_item_select_keys:
+ main_form_key = key + self.url_name
+ try:
+ idx = int(self.session_get_value(main_form_key,
+ self.current_object_key))
+ current_obj = self.model.objects.get(pk=idx)
+ break
+ except(TypeError, ValueError, ObjectDoesNotExist):
+ pass
return current_obj
def get_form_initial(self, step, data=None):
current_obj = self.get_current_object()
current_step = self.steps.current
request = self.request
- if step.startswith('selec-') and step in self.form_list \
+ step_is_main_select = bool([k for k in self.main_item_select_keys
+ if step.startswith(k)])
+ if step_is_main_select and step in self.form_list \
and 'pk' in self.form_list[step].associated_models:
model_name = self.form_list[step]\
.associated_models['pk'].__name__.lower()