comparison src/server/pages.py @ 1031:4ba7df23b976

pages: new method getURLByNames to retrieve URL from list of page names/path arguments
author Goffi <goffi@goffi.org>
date Mon, 22 Jan 2018 22:17:20 +0100
parents 66a050b32df8
children 863cc6f97068
comparison
equal deleted inserted replaced
1030:66a050b32df8 1031:4ba7df23b976
487 """ 487 """
488 current_url = self.getCurrentURL(request) 488 current_url = self.getCurrentURL(request)
489 path, child = self.getSubPageByName(self, page_name) 489 path, child = self.getSubPageByName(self, page_name)
490 return os.path.join(u'/', current_url, path, *[quote(a) for a in args]) 490 return os.path.join(u'/', current_url, path, *[quote(a) for a in args])
491 491
492 def getURLByNames(self, named_path):
493 """retrieve URL from pages names and arguments
494
495 @param named_path(list[tuple[unicode, list[unicode]]]): path to the page as a list
496 of tuples of 2 items:
497 - first item is page name
498 - second item is list of path arguments of this page
499 @return (unicode): URL to the requested page with given path arguments
500 @raise exceptions.NotFound: one of the page was not found
501 """
502 current_page = None
503 path = []
504 for page_name, page_args in named_path:
505 if current_page is None:
506 current_page = self.getPageByName(page_name)
507 path.append(current_page.getURL(*page_args))
508 else:
509 sub_path, current_page = self.getSubPageByName(current_page, page_name)
510 path.append(sub_path)
511 if page_args:
512 path.extend([quote(a) for a in page_args])
513 return u'/'.join(path)
492 514
493 def getChildWithDefault(self, path, request): 515 def getChildWithDefault(self, path, request):
494 # we handle children ourselves 516 # we handle children ourselves
495 raise exceptions.InternalError(u"this method should not be used with LiberviaPage") 517 raise exceptions.InternalError(u"this method should not be used with LiberviaPage")
496 518