diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-08-12 12:09:41 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-08-12 12:09:41 +0200 |
commit | 6e89d666ffcadd6dda441c0381d09377227dbc38 (patch) | |
tree | 31622f4050a7fd91443b42545265972e23ee85de /ishtar_common | |
parent | 4ad9278e67d8fb024c685df03812c2e1d8313aa1 (diff) | |
parent | f0b43bb86aea222f00afca37a97407aca0b7e867 (diff) | |
download | Ishtar-6e89d666ffcadd6dda441c0381d09377227dbc38.tar.bz2 Ishtar-6e89d666ffcadd6dda441c0381d09377227dbc38.zip |
Merge branch 'master-pdl'
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/wizards.py | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 49abe606f..8bb0dc00b 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -91,6 +91,25 @@ def check_rights_condition(rights): return func +def _check_right(step, condition=True): + '''Return a method to check the right for a specific step''' + def check_right(self): + cond = condition + # TODO: cond.__name__ != 'check_right' prevent unexplicated + # infinite loop... to be fixed + if callable(cond) and cond.__name__ != 'check_right': + cond = cond(self) + if not cond: + return False + return True + # TODO: to be check + if not hasattr(self.request.user, 'ishtaruser'): + return False + return self.request.user.ishtaruser.has_right( + ('administrator', step), session=self.request.session) + return check_right + + class Wizard(NamedUrlWizardView): model = None label = '' @@ -105,31 +124,12 @@ class Wizard(NamedUrlWizardView): filter_owns = {} current_obj_slug = '' - @staticmethod - def _check_right(step, condition=True): - '''Return a method to check the right for a specific step''' - def check_right(self): - cond = condition - if callable(condition): - cond = condition(self) - if not cond: - return False - return True - # TODO: to be check - if not hasattr(self.request.user, 'ishtaruser'): - return False - return self.request.user.ishtaruser.has_right( - ('administrator', step), session=self.request.session) - return check_right - def __init__(self, *args, **kwargs): """Check right for each step of the wizard""" super(Wizard, self).__init__(*args, **kwargs) for form_key in self.form_list.keys()[:-1]: - condition = True - if form_key in self.condition_dict: - condition = self.condition_dict.get(form_key, True) - cond = self._check_right(form_key, condition) + condition = self.condition_dict.get(form_key, True) + cond = _check_right(form_key, condition) self.condition_dict[form_key] = cond def dispatch(self, request, *args, **kwargs): |