diff options
Diffstat (limited to 'ishtar_common/wizards.py')
-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 e974942b7..48ea03e24 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): |