summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-09-02 20:13:11 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-09-02 20:13:11 +0200
commitaf1c007c74a36e04afd5a29b2d7d5c8e82f4e3a3 (patch)
treef6a1d026f941a49d09059ca50fbfaa57ab7c51aa
parent3ed75b037e8e79408f8eca990b80aa878f25706d (diff)
downloadIshtar-af1c007c74a36e04afd5a29b2d7d5c8e82f4e3a3.tar.bz2
Ishtar-af1c007c74a36e04afd5a29b2d7d5c8e82f4e3a3.zip
Display every steps when modifying (refs #438)
-rw-r--r--ishtar/ishtar_base/forms.py38
-rw-r--r--ishtar/ishtar_base/forms_files.py5
-rw-r--r--ishtar/ishtar_base/forms_operations.py2
-rw-r--r--ishtar/templates/default_wizard.html4
4 files changed, 40 insertions, 9 deletions
diff --git a/ishtar/ishtar_base/forms.py b/ishtar/ishtar_base/forms.py
index e4f52b1cd..287a181f4 100644
--- a/ishtar/ishtar_base/forms.py
+++ b/ishtar/ishtar_base/forms.py
@@ -105,6 +105,7 @@ class SearchWizard(NamedUrlSessionFormWizard):
class Wizard(NamedUrlSessionFormWizard):
model = None
+ modification = None # True when the wizard modify an item
def get_wizard_name(self):
"""
@@ -122,7 +123,7 @@ class Wizard(NamedUrlSessionFormWizard):
def get_template_context(self, request, storage, form=None):
"""
- Add previous and current steps to manage the wizard path
+ Add previous, next and current steps to manage the wizard path
"""
context = super(Wizard, self).get_template_context(request, storage,
form)
@@ -132,13 +133,38 @@ class Wizard(NamedUrlSessionFormWizard):
context.update({'current_step':self.form_list[current_step]})
if step == current_step:
return context
- previous_steps = []
+ previous_steps, next_steps, previous_step_counter = [], [], 0
while step:
if step == current_step:
break
previous_steps.append(self.form_list[step])
step = self.get_next_step(request, storage, step)
- context.update({'previous_steps':previous_steps})
+ previous_step_counter += 1
+ context.update({'previous_steps':previous_steps,
+ 'previous_step_counter':previous_step_counter})
+ # if modification: show the next steps
+ next_step = step
+ if self.modification:
+ while next_step:
+ # check if the form is initialized otherwise initialize it
+ if not storage.get_step_data(next_step):
+ values = self.get_form_initial(request, storage, next_step)
+ prefixed_values = {}
+ if not isinstance(values, list):
+ for key in values:
+ form_key = next_step + '-' + key
+ prefixed_values[form_key] = values[key]
+ else:
+ for formset_idx, v in enumerate(values):
+ prefix = u"-%d-" % formset_idx
+ for key in v:
+ form_key = next_step + prefix + key
+ prefixed_values[form_key] = v[key]
+ storage.set_step_data(next_step, prefixed_values)
+ if step != next_step: # if not current step
+ next_steps.append(self.form_list[next_step])
+ next_step = self.get_next_step(request, storage, next_step)
+ context.update({'next_steps':next_steps})
# not last step: validation
if step != self.get_last_step(request, storage):
return context
@@ -582,12 +608,12 @@ class Wizard(NamedUrlSessionFormWizard):
return initial
return super(Wizard, self).get_form_initial(request, storage, step)
- def get_instanced_init(self, obj, request, storage, step):
+ def get_instanced_init(self, obj, request, storage, step=None):
"""
Get initial data from an init
"""
- current_step = storage.get_current_step() or self.get_first_step(
- request, storage)
+ current_step = step or storage.get_current_step() \
+ or self.get_first_step(request, storage)
c_form = self.form_list[current_step]
# make the current object the default item for the session
obj_name = obj.__class__.__name__.lower()
diff --git a/ishtar/ishtar_base/forms_files.py b/ishtar/ishtar_base/forms_files.py
index 61db92fa5..8fd9df926 100644
--- a/ishtar/ishtar_base/forms_files.py
+++ b/ishtar/ishtar_base/forms_files.py
@@ -259,7 +259,10 @@ file_creation_wizard = FileWizard([
},
url_name='file_creation',)
-file_modification_wizard = FileWizard([
+class FileModificationWizard(FileWizard):
+ modification = True
+
+file_modification_wizard = FileModificationWizard([
('selec-file_modification', FileFormSelection),
('general-file_modification', FileFormGeneralRO),
('adress-file_modification', FileFormAddress),
diff --git a/ishtar/ishtar_base/forms_operations.py b/ishtar/ishtar_base/forms_operations.py
index 3227e8d84..3d149577a 100644
--- a/ishtar/ishtar_base/forms_operations.py
+++ b/ishtar/ishtar_base/forms_operations.py
@@ -519,7 +519,6 @@ class OperationSourceWizard(SourceWizard):
storage, step)
# put default index and operation_id field in the main source form
general_form_key = 'selec-' + self.url_name
- print "hop"
if step.startswith('source-') \
and self.session_has_key(request, storage, general_form_key):
gen_storage = request.session[storage.prefix]['step_data']\
@@ -528,7 +527,6 @@ class OperationSourceWizard(SourceWizard):
operation_id = int(gen_storage[general_form_key+"-operation"])
elif general_form_key+"-pk" in gen_storage:
pk = int(gen_storage[general_form_key+"-pk"])
- print pk
try:
source = models.OperationSource.objects.get(pk=pk)
operation_id = source.operation.pk
diff --git a/ishtar/templates/default_wizard.html b/ishtar/templates/default_wizard.html
index 9988180d9..561206d23 100644
--- a/ishtar/templates/default_wizard.html
+++ b/ishtar/templates/default_wizard.html
@@ -12,6 +12,9 @@
<li>&raquo;&nbsp;<button name="form_prev_step" value="{{forloop.counter0}}">{{step.form_label}}</button></li>
{% endfor %}
<li class='current'>&raquo;&nbsp;<a href='#'>{{current_step.form_label}}</a></li>
+{% for step in next_steps %}
+ <li>&raquo;&nbsp;<button name="form_prev_step" value="{{forloop.counter|add:previous_step_counter}}">{{step.form_label}}</button></li>
+{% endfor %}
</ul>
<div class='form'>
{% if reminder %}<div class='reminder'>{{ reminder }}</div>{%endif%}
@@ -33,6 +36,7 @@
<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
{{ previous_fields|safe }}
<input type="submit" id="submit_form" value="{% trans "Validate" %}"/>
+{% if next_steps %}<input type="submit" id="submit_end_form" value="{% trans "Validate and end" %}"/>{% endif %}
</div>
</form>
{% endblock %}