diff src/server/pages.py @ 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 64826e69f365
children b92b06f023cb
line wrap: on
line diff
--- 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):