diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-12-27 19:28:30 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-12-27 19:28:30 +0100 |
commit | a4f635716015c9f5ed5e6bcd2564da49a2b7f458 (patch) | |
tree | 81a1d5b05161182a1686f8b2f530d36cb66bb6a1 | |
parent | a8f2bf3258897d1724ac21df4803880939ad334b (diff) | |
download | Ishtar-a4f635716015c9f5ed5e6bcd2564da49a2b7f458.tar.bz2 Ishtar-a4f635716015c9f5ed5e6bcd2564da49a2b7f458.zip |
Basic work on menus (refs #50)
-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 | ||||
-rw-r--r-- | ishtar/templates/base.html | 12 | ||||
-rw-r--r-- | ishtar/templates/registration/logout.html | 2 | ||||
-rw-r--r-- | ishtar/urls.py | 4 |
6 files changed, 99 insertions, 3 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)) diff --git a/ishtar/templates/base.html b/ishtar/templates/base.html index e26a5ddab..ff9744391 100644 --- a/ishtar/templates/base.html +++ b/ishtar/templates/base.html @@ -29,7 +29,17 @@ {% block context %}{% endblock %} </div> <div id="main_menu"> - {% block menu %}{% endblock %} + <ul> + {% for section in MENU.childs %} + <li>{{section.label}} + <ul> + {% for menu_item in section.childs %} + <li><a href='{% url action menu_item.idx%}'>{{menu_item.label}}</a></li> + {% endfor %} + </ul> + </li> + {% endfor %} + </ul> </div> <div id="content"> {% block content %}{% endblock %} diff --git a/ishtar/templates/registration/logout.html b/ishtar/templates/registration/logout.html index 399d8c343..029a0c25b 100644 --- a/ishtar/templates/registration/logout.html +++ b/ishtar/templates/registration/logout.html @@ -2,7 +2,7 @@ {% load i18n %} {% block content %} -<div class='form'> +<div class='info'> <p>{% trans "Logged out" %}</p> </div> {% endblock %} diff --git a/ishtar/urls.py b/ishtar/urls.py index 9f58a3e56..b9369ce06 100644 --- a/ishtar/urls.py +++ b/ishtar/urls.py @@ -12,4 +12,6 @@ urlpatterns = patterns('', (BASE_URL + r'admin/', include(admin.site.urls)), ) urlpatterns += patterns('ishtar.furnitures.views', - url(BASE_URL + '$', 'index', name='start'),) + url(BASE_URL + '$', 'index', name='start'), + url(BASE_URL + '(?P<action>\w+)/$', 'action', name='action'), + ) |