summaryrefslogtreecommitdiff
path: root/archaeological_operations/wizards.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/wizards.py')
-rw-r--r--archaeological_operations/wizards.py36
1 files changed, 33 insertions, 3 deletions
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py
index 2b13e3353..4205144e6 100644
--- a/archaeological_operations/wizards.py
+++ b/archaeological_operations/wizards.py
@@ -27,16 +27,19 @@ from django.utils.translation import ugettext_lazy as _
from ishtar_common.wizards import Wizard, ClosingWizard, DeletionWizard, \
SourceWizard
import models
+from forms import ParcelForm
class OperationWizard(Wizard):
model = models.Operation
object_parcel_type = 'operation'
+ parcel_step_key = 'parcelsgeneral-'
def get_template_names(self):
templates = super(OperationWizard, self).get_template_names()
current_step = self.steps.current
if current_step.startswith('towns-'):
- templates = ['ishtar/wizard/towns_wizard.html'] + templates
+ #templates = ['ishtar/wizard/towns_wizard.html'] + templates
+ pass
if current_step.startswith('parcels-') or \
current_step.startswith('parcelsgeneral-') :
templates = ['ishtar/wizard/parcels_wizard.html'] + templates
@@ -124,7 +127,7 @@ class OperationWizard(Wizard):
Show a specific warning if no archaelogical file is provided
"""
datas = super(OperationWizard, self).get_formated_datas(forms)
- # if the general town form is used the advertissement is pertinent
+ # if the general town form is used the advertissement is relevant
has_no_af = [form.prefix for form in forms
if form.prefix == 'townsgeneral-operation'] and True
if has_no_af:
@@ -133,6 +136,33 @@ class OperationWizard(Wizard):
+ datas
return datas
+ def get_form_initial(self, step, data=None):
+ initial = super(OperationWizard, self).get_form_initial(step)
+ self.form_initialized = False
+ if not step.startswith(self.parcel_step_key):
+ return initial
+ if initial:
+ default = initial[-1].copy()
+ if 'parcel_number' in default:
+ default.pop('parcel_number')
+ initial.append(default)
+ # necessary to get the appropriate form number
+ self.form_initialized = True
+ elif data:
+ numbers, keys = set(), set()
+ for k in data:
+ items = k.split('-')
+ try:
+ numbers.add(int(items[-2]))
+ except (ValueError, IndexError):
+ continue
+ keys.add(items[-1])
+ if max(numbers) - 1:
+ initial = [dict([(k, data[step+'-'+unicode(max(numbers)-1)+'-'+k])
+ for k in keys if k != 'parcel_number'])]
+ self.form_initialized = True
+ return initial
+
class OperationModificationWizard(OperationWizard):
modification = True
@@ -148,7 +178,7 @@ class OperationDeletionWizard(DeletionWizard):
class OperationSourceWizard(SourceWizard):
model = models.OperationSource
- def get_form_initial(self, step):
+ def get_form_initial(self, step, data=None):
initial = super(OperationSourceWizard, self).get_form_initial(step)
# put default index and operation_id field in the main source form
general_form_key = 'selec-' + self.url_name