diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-03-21 19:18:15 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-03-21 19:18:15 +0100 |
commit | 76eeffe1354cad5683f499cbc68669d1d5237de5 (patch) | |
tree | f89afc90cf5c0465404beeb218cb1ff05020428c /ishtar_common | |
parent | 3589e3fda2c3acc49632f1e3a1a5255a5f5c7724 (diff) | |
download | Ishtar-76eeffe1354cad5683f499cbc68669d1d5237de5.tar.bz2 Ishtar-76eeffe1354cad5683f499cbc68669d1d5237de5.zip |
Finds search: conditionnal search (warehouse module available) for warehouses and containers (refs #3416)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/wizards.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 874b68eae..7950bcc7e 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -132,6 +132,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 +218,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: @@ -1004,20 +1006,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() |