summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-02-08 02:31:55 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-02-08 02:31:55 +0100
commitc70af314a07f8b1ad84cf8b55806714ed408b6f1 (patch)
tree00a5895af500d0c1d5785d31c1def309cf1b563c /ishtar_common
parentb0a48f170a51b7239960aadcc501e23b9af339c2 (diff)
downloadIshtar-c70af314a07f8b1ad84cf8b55806714ed408b6f1.tar.bz2
Ishtar-c70af314a07f8b1ad84cf8b55806714ed408b6f1.zip
Fix default item after creations
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/views.py5
-rw-r--r--ishtar_common/wizards.py20
2 files changed, 17 insertions, 8 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 981522d0d..ae02e0c5f 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -398,11 +398,12 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
q = Q(**{req_key: val})
reqs = reqs | q
and_reqs.append(reqs)
- if not dct and 'submited' not in request_items:
+ print(default_name, dct)
+ if 'submited' not in request_items:
if default_name in request.session and \
request.session[default_name]:
dct = {"pk": request.session[default_name]}
- else:
+ elif not dct:
for name in relative_session_names.keys():
if name in request.session and request.session[name]:
k = relative_session_names[name]
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index ffbf9b994..0b121fd76 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -103,6 +103,7 @@ class Wizard(NamedUrlWizardView):
wizard_confirm = 'ishtar/wizard/confirm_wizard.html'
wizard_templates = {}
filter_owns = {}
+ current_obj_slug = ''
@staticmethod
def _check_right(step, condition=True):
@@ -592,6 +593,10 @@ class Wizard(NamedUrlWizardView):
# necessary to manage interaction between models like
# material_index management for baseitems
obj.save()
+ # make the new object a default
+ if self.current_obj_slug:
+ self.request.session[self.current_obj_slug] = unicode(obj.pk)
+ self.request.session[self.get_object_name(obj)] = unicode(obj.pk)
dct = {'item': obj}
# force evaluation of lazy urls
wizard_done_window = unicode(self.wizard_done_window)
@@ -876,17 +881,20 @@ class Wizard(NamedUrlWizardView):
return initial
return super(Wizard, self).get_form_initial(step)
- def get_instanced_init(self, obj, step=None):
- """Get initial data from an init"""
- current_step = step or self.steps.current
- c_form = self.form_list[current_step]
- # make the current object the default item for the session
+ def get_object_name(self, obj):
obj_name = obj.__class__.__name__.lower()
# prefer a specialized name if available
prefixes = self.storage.prefix.split('_')
if len(prefixes) > 1 and prefixes[-2].startswith(obj_name):
obj_name = prefixes[-2]
- self.request.session[obj_name] = unicode(obj.pk)
+ return obj_name
+
+ def get_instanced_init(self, obj, step=None):
+ """Get initial data from an init"""
+ current_step = step or self.steps.current
+ c_form = self.form_list[current_step]
+ # make the current object the default item for the session
+ self.request.session[self.get_object_name(obj)] = unicode(obj.pk)
initial = MultiValueDict()
if self.request.POST or \
(step in self.request.session[self.storage.prefix] and