diff options
Diffstat (limited to 'ishtar_common/menu_base.py')
| -rw-r--r-- | ishtar_common/menu_base.py | 31 | 
1 files changed, 29 insertions, 2 deletions
| diff --git a/ishtar_common/menu_base.py b/ishtar_common/menu_base.py index ab0a43d41..eb08d8c78 100644 --- a/ishtar_common/menu_base.py +++ b/ishtar_common/menu_base.py @@ -17,16 +17,28 @@  # See the file COPYING for details. +from ishtar_common.models import get_current_profile +  class SectionItem: -    def __init__(self, idx, label, childs=[]): +    def __init__(self, idx, label, childs=[], profile_restriction=None):          self.idx = idx          self.label = label          self.childs = childs          self.available = False          self.items = {} +        self.profile_restriction = profile_restriction + +    def check_profile_restriction(self): +        if self.profile_restriction: +            profile = get_current_profile() +            if not getattr(profile, self.profile_restriction): +                return False +        return True      def can_be_available(self, user, session=None): +        if not self.check_profile_restriction(): +            return False          for child in self.childs:              if child.can_be_available(user, session=session):                  return True @@ -50,14 +62,27 @@ class SectionItem:  class MenuItem: -    def __init__(self, idx, label, model=None, access_controls=[]): +    def __init__(self, idx, label, model=None, access_controls=[], +                 profile_restriction=None):          self.idx = idx          self.label = label          self.model = model          self.access_controls = access_controls          self.available = False +        self.profile_restriction = profile_restriction +        if not self.check_profile_restriction(): +            return False + +    def check_profile_restriction(self): +        if self.profile_restriction: +            profile = get_current_profile() +            if not getattr(profile, self.profile_restriction): +                return False +        return True      def can_be_available(self, user, session=None): +        if not self.check_profile_restriction(): +            return False          if not self.access_controls:              return True          prefix = (self.model._meta.app_label + '.') if self.model else '' @@ -75,6 +100,8 @@ class MenuItem:          return False      def is_available(self, user, obj=None, session=None): +        if not self.check_profile_restriction(): +            return False          if not self.access_controls:              return True          prefix = (self.model._meta.app_label + '.') if self.model else '' | 
