37 lines
1004 B
Python
37 lines
1004 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
class Menu(object):
|
|
menuitems = [
|
|
('Main page', 'gva', 'index', None),
|
|
('Login', 'login', 'login', []),
|
|
('Logout', 'login', 'logout', ['*']),
|
|
('Admin', 'gva', 'index', ['admin'])
|
|
]
|
|
|
|
@classmethod
|
|
def allowed(cls, roles=[]):
|
|
items = []
|
|
for item in cls.menuitems:
|
|
additem = False
|
|
if item[3] is None:
|
|
additem = True
|
|
elif len(item[3]) == 0 and len(roles) == 0:
|
|
additem = True
|
|
elif len(roles) > 0:
|
|
for role in item[3]:
|
|
if role in roles or role == '*':
|
|
additem = True
|
|
break
|
|
if additem:
|
|
items.append(Menu(item[0], item[1], item[2]))
|
|
return items
|
|
|
|
def __init__(self, title, controller, action):
|
|
self.title = title
|
|
self.controller = controller
|
|
self.action = action
|
|
|
|
|
|
|
|
|