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 | f7a4bd783df87aea052aba07b2a48001b6389772 (patch) | |
| tree | f89afc90cf5c0465404beeb218cb1ff05020428c /ishtar_common/wizards.py | |
| parent | f164cd8f9107b1c6a803fa6fe6adda52539f8b8f (diff) | |
| download | Ishtar-f7a4bd783df87aea052aba07b2a48001b6389772.tar.bz2 Ishtar-f7a4bd783df87aea052aba07b2a48001b6389772.zip | |
Finds search: conditionnal search (warehouse module available) for warehouses and containers (refs #3416)
Diffstat (limited to 'ishtar_common/wizards.py')
| -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() | 
