diff options
Diffstat (limited to 'ishtar/furnitures')
| -rw-r--r-- | ishtar/furnitures/context_processors.py | 7 | ||||
| -rw-r--r-- | ishtar/furnitures/menus.py | 70 | ||||
| -rw-r--r-- | ishtar/furnitures/views.py | 7 |
3 files changed, 84 insertions, 0 deletions
diff --git a/ishtar/furnitures/context_processors.py b/ishtar/furnitures/context_processors.py index ae1bbc36d..e187d2f76 100644 --- a/ishtar/furnitures/context_processors.py +++ b/ishtar/furnitures/context_processors.py @@ -18,10 +18,17 @@ # See the file COPYING for details. from ishtar import settings +from menus import Menu def get_base_context(request): dct = {} if settings.APP_NAME: dct["APP_NAME"] = settings.APP_NAME + if 'MENU' not in request.session or \ + request.session['MENU'].user != request.user: + menu = Menu(request.user) + menu.init() + request.session['MENU'] = menu + dct['MENU'] = request.session['MENU'] return dct diff --git a/ishtar/furnitures/menus.py b/ishtar/furnitures/menus.py new file mode 100644 index 000000000..5a2446f79 --- /dev/null +++ b/ishtar/furnitures/menus.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2010 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> + +# 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 <http://www.gnu.org/licenses/>. + +# 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 + + diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index 9ec293ee8..cce399d1f 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -33,4 +33,11 @@ def index(request): dct = {} return render_to_response('index.html', dct, context_instance=RequestContext(request)) +def action(request, action): + """ + Main page + """ + dct = {} + return render_to_response('index.html', dct, + context_instance=RequestContext(request)) |
