Mercurial > libervia-web
changeset 990:6daa59d44ee2
pages: menu implementation, first draft:
menu can now be specified in sat.conf using menu_json setting and using pages' names.
A default menu is set in constants, with only login and blog pages for now.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Dec 2017 00:02:34 +0100 |
parents | 1d1a6c91961f |
children | 6ce9647011b3 |
files | src/server/constants.py src/server/pages.py src/server/server.py src/twisted/plugins/libervia_server.py |
diffstat | 4 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/server/constants.py Thu Nov 30 21:05:24 2017 +0100 +++ b/src/server/constants.py Fri Dec 01 00:02:34 2017 +0100 @@ -57,6 +57,8 @@ PAGES_ACCESS_PROFILE = u"profile" # a session with an existing profile must be started PAGES_ACCESS_ADMIN = u"admin" # only profiles set in admins_list can access the page PAGES_ACCESS_ALL = (PAGES_ACCESS_NONE, PAGES_ACCESS_PUBLIC, PAGES_ACCESS_PROFILE, PAGES_ACCESS_ADMIN) + # names of the page to use for menu + DEFAULT_MENU = ['login', 'blog_view'] ## Session flags ## FLAG_CONFIRM = u"CONFIRM"
--- a/src/server/pages.py Thu Nov 30 21:05:24 2017 +0100 +++ b/src/server/pages.py Fri Dec 01 00:02:34 2017 +0100 @@ -71,6 +71,7 @@ # Set of tuples (service/node/sub_id) of nodes subscribed for caching # sub_id can be empty string if not handled by service cache_pubsub_sub = set() + main_menu = None def __init__(self, host, root_dir, url, name=None, redirect=None, access=None, parse_url=None, prepare_render=None, render=None, template=None, on_data_post=None): @@ -227,6 +228,22 @@ LiberviaPage.importPages(host, resource, new_path) @classmethod + def setMenu(cls, menus): + main_menu = [] + for menu in menus: + if not menu: + raise ValueError(_(u"menu item can't be empty")) + elif isinstance(menu, list): + if len(menu) != 2: + raise ValueError(_(u"menu item as list must be in the form [page_name, absolue URL]")) + page_name, url = menu + else: + page_name = menu + url = cls.getPageByName(page_name).url + main_menu.append((page_name, url)) + cls.main_menu = main_menu + + @classmethod def registerURI(cls, uri_tuple, get_uri_cb, pre_path): """register a URI handler @@ -587,6 +604,7 @@ self.template, root_path = '/templates/', media_path = '/' + C.MEDIA_DIR, + main_menu = LiberviaPage.main_menu, **template_data) def _renderEb(self, failure_, request):
--- a/src/server/server.py Thu Nov 30 21:05:24 2017 +0100 +++ b/src/server/server.py Fri Dec 01 00:02:34 2017 +0100 @@ -1453,6 +1453,7 @@ self.putChild(C.THEMES_URL, ProtectedFile(self.themes_dir)) LiberviaPage.importPages(self) + LiberviaPage.setMenu(self.options['menu_json']) self.bridge.register_signal("psEventRaw", partial(LiberviaPage.onNodeEvent, self), "plugin") # media dirs
--- a/src/twisted/plugins/libervia_server.py Thu Nov 30 21:05:24 2017 +0100 +++ b/src/twisted/plugins/libervia_server.py Fri Dec 01 00:02:34 2017 +0100 @@ -117,6 +117,7 @@ ['empty_password_allowed_warning_dangerous_list', None, '', None], ['url_redirections_profile', None, '', None], ['url_redirections_dict', None, {}, None], + ['menu_json', None, C.DEFAULT_MENU, None], ] def initialise(options):