comparison 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
comparison
equal deleted inserted replaced
989:1d1a6c91961f 990:6daa59d44ee2
69 pages_redirects = {} 69 pages_redirects = {}
70 cache = {} 70 cache = {}
71 # Set of tuples (service/node/sub_id) of nodes subscribed for caching 71 # Set of tuples (service/node/sub_id) of nodes subscribed for caching
72 # sub_id can be empty string if not handled by service 72 # sub_id can be empty string if not handled by service
73 cache_pubsub_sub = set() 73 cache_pubsub_sub = set()
74 main_menu = None
74 75
75 def __init__(self, host, root_dir, url, name=None, redirect=None, access=None, parse_url=None, 76 def __init__(self, host, root_dir, url, name=None, redirect=None, access=None, parse_url=None,
76 prepare_render=None, render=None, template=None, on_data_post=None): 77 prepare_render=None, render=None, template=None, on_data_post=None):
77 """initiate LiberviaPages 78 """initiate LiberviaPages
78 79
225 cls.registerURI(uri_tuple, cb, new_path) 226 cls.registerURI(uri_tuple, cb, new_path)
226 227
227 LiberviaPage.importPages(host, resource, new_path) 228 LiberviaPage.importPages(host, resource, new_path)
228 229
229 @classmethod 230 @classmethod
231 def setMenu(cls, menus):
232 main_menu = []
233 for menu in menus:
234 if not menu:
235 raise ValueError(_(u"menu item can't be empty"))
236 elif isinstance(menu, list):
237 if len(menu) != 2:
238 raise ValueError(_(u"menu item as list must be in the form [page_name, absolue URL]"))
239 page_name, url = menu
240 else:
241 page_name = menu
242 url = cls.getPageByName(page_name).url
243 main_menu.append((page_name, url))
244 cls.main_menu = main_menu
245
246 @classmethod
230 def registerURI(cls, uri_tuple, get_uri_cb, pre_path): 247 def registerURI(cls, uri_tuple, get_uri_cb, pre_path):
231 """register a URI handler 248 """register a URI handler
232 249
233 @param uri_tuple(tuple[unicode, unicode]): type or URIs handler 250 @param uri_tuple(tuple[unicode, unicode]): type or URIs handler
234 type/subtype as returned by tools/common/parseXMPPUri 251 type/subtype as returned by tools/common/parseXMPPUri
585 602
586 return self.host.renderer.render( 603 return self.host.renderer.render(
587 self.template, 604 self.template,
588 root_path = '/templates/', 605 root_path = '/templates/',
589 media_path = '/' + C.MEDIA_DIR, 606 media_path = '/' + C.MEDIA_DIR,
607 main_menu = LiberviaPage.main_menu,
590 **template_data) 608 **template_data)
591 609
592 def _renderEb(self, failure_, request): 610 def _renderEb(self, failure_, request):
593 """don't raise error on CancelError""" 611 """don't raise error on CancelError"""
594 failure_.trap(exceptions.CancelError) 612 failure_.trap(exceptions.CancelError)