summaryrefslogtreecommitdiff
path: root/ishtar_common/menu_base.py
diff options
context:
space:
mode:
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
commit2d8c714fe516361c2a47eba30542ae57452de22f (patch)
treea7256183a32a204ac4e90e2503483c5ffc1f33db /ishtar_common/menu_base.py
parentb3856fc87277daa856292b71b51381f139c2fdf3 (diff)
downloadIshtar-2d8c714fe516361c2a47eba30542ae57452de22f.tar.bz2
Ishtar-2d8c714fe516361c2a47eba30542ae57452de22f.zip
New management of modules
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 ''