diff options
-rw-r--r-- | archaeological_files_pdl/wizards.py | 3 | ||||
-rw-r--r-- | archaeological_operations/wizards.py | 18 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 8 |
3 files changed, 20 insertions, 9 deletions
diff --git a/archaeological_files_pdl/wizards.py b/archaeological_files_pdl/wizards.py index f91355ea4..b62f8ebdb 100644 --- a/archaeological_files_pdl/wizards.py +++ b/archaeological_files_pdl/wizards.py @@ -25,7 +25,8 @@ class FileWizard(BaseFileWizard): parcel_step_key = 'parcelspdl-' town_step_keys = ['preventiveplanning-', 'researchaddress-'] town_input_id = 'town' - multi_towns = False + towns_formset = False + multi_towns = True wizard_templates = { 'generalcontractor-%(url_name)s': 'ishtar/wizard/wizard_generalcontractor.html', diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 93787fca2..cbc5a20c5 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -39,11 +39,12 @@ if FILES_AVAILABLE: class OperationWizard(Wizard): model = models.Operation object_parcel_type = 'operation' - parcel_step_key = 'parcelsgeneral-' + parcel_step_key = 'parcels' # step contening the current(s) town(s) town_step_keys = ['towns-', 'townsgeneral-'] town_input_id = 'town' # input id of the current(s) town(s) - multi_towns = True # true if current town are multi + multi_towns = False # true if current town are multi valued + towns_formset = True # true if towns are managed with formset wizard_done_window = reverse_lazy('show-operation') def get_template_names(self): @@ -161,9 +162,11 @@ class OperationWizard(Wizard): town_form_key = town_step_key + self.url_name town_ids = self.session_get_value( town_form_key, self.town_input_id, - multi=self.multi_towns) or [] - if town_ids and type(town_ids) == unicode: - town_ids = town_ids.split(',') + multi=self.towns_formset, + multi_value=self.multi_towns) or [] + if town_ids: + if type(town_ids) == unicode: + town_ids = town_ids.split(',') break if type(town_ids) not in (list, tuple): town_ids = [town_ids] @@ -244,7 +247,8 @@ class OperationWizard(Wizard): file = self.get_current_file() if not file: return super(OperationWizard, self).post(*args, **kwargs) - parcel_form_key = "parcels-" + self.url_name + parcel_form_key = self.steps.current + # parcel_form_key = "parcels-" + self.url_name idx = -1 # remove non relevant deleted keys for k in post_data.keys(): @@ -253,7 +257,7 @@ class OperationWizard(Wizard): for idx, parcel in enumerate(self.get_available_parcels(file)): parcel_pk, parcel_name = parcel post_data["%s-%d-parcel" % (parcel_form_key, idx)] = parcel_pk - post_data[parcel_form_key + '-TOTAL_FORMS'] = idx + 1 + post_data[parcel_form_key + '-TOTAL_FORMS'] = idx + 2 request.POST = post_data return super(OperationWizard, self).post(*args, **kwargs) diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index c8b017293..b3e5c4122 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -668,7 +668,7 @@ class Wizard(NamedUrlWizardView): data[key] = value storage.set_step_data(form_key, data) - def session_get_value(self, form_key, key, multi=False): + def session_get_value(self, form_key, key, multi=False, multi_value=False): """Get the value of a specific form""" if not self.session_has_key(form_key, key, multi): return @@ -678,7 +678,13 @@ class Wizard(NamedUrlWizardView): key = key.startswith(form_key) and key or form_key + '-' + key val = request.session[storage.prefix]['step_data'][form_key][key] if type(val) in (list, tuple) and val: + if multi_value: + return val val = val[0] + elif multi_value: + if val: + return [val] + return [] return val vals = [] for k in request.session[storage.prefix]['step_data'][form_key]: |