diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-02-18 01:05:08 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-02-18 01:05:08 +0100 |
commit | 50b565e74631a684b2b389cac55982db86d8d5ba (patch) | |
tree | a7256183a32a204ac4e90e2503483c5ffc1f33db /ishtar_common/menu_base.py | |
parent | 5e47cbfcbeb090762547042d809016074bf1c679 (diff) | |
download | Ishtar-50b565e74631a684b2b389cac55982db86d8d5ba.tar.bz2 Ishtar-50b565e74631a684b2b389cac55982db86d8d5ba.zip |
New management of modules
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 '' |