summaryrefslogtreecommitdiff
path: root/ishtar_common/menu_base.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-02-26 20:52:11 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-02-26 20:52:11 +0100
commitf72f7d90893b4f4ae0e000563b7c20faeefc8f18 (patch)
tree8c8f06c9fb974edde62e82875f7a1b8aad49d7c3 /ishtar_common/menu_base.py
parent90b20a15bd6bf4f7808957bb8820f10f0d66d5e8 (diff)
parent0cd8904defe334ad5307e6ab3ce13638479815a8 (diff)
downloadIshtar-f72f7d90893b4f4ae0e000563b7c20faeefc8f18.tar.bz2
Ishtar-f72f7d90893b4f4ae0e000563b7c20faeefc8f18.zip
Merge branch 'master' into v0.9
Diffstat (limited to 'ishtar_common/menu_base.py')
-rw-r--r--ishtar_common/menu_base.py31
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 ''