#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2010 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # See the file COPYING for details. """ Menus """ from django.utils.translation import ugettext_lazy as _ class SectionItem: def __init__(self, idx, label, childs=[]): self.idx = idx self.label = label self.childs = childs self.available = False class MenuItem: def __init__(self, idx, label, groups=[]): self.idx = idx self.label = label self.groups = groups self.available = False def is_available(self, user): return True class Menu: def __init__(self, user): self.user = user self.initialized = False self.childs = [ SectionItem('file_management', _(u"File management"), childs=[ MenuItem('file_creation', _(u"File creation"), groups=['administrator']), MenuItem('file_modification', _(u"File modification"), groups=['administrator']), MenuItem('file_deletion', _(u"File deletion"), groups=['administrator']), ]), ] def init(self): if self.initialized: return for main_menu in self.childs: main_menu.available = False for child in main_menu.childs: child.available = child.is_available(self.user) if child.available: main_menu.available = True self.initialized = True