# HG changeset patch # User Goffi # Date 1516655840 -3600 # Node ID 4ba7df23b97680379c586930203db8f746f430dc # Parent 66a050b32df8603b4eb64809562d00516b32233c pages: new method getURLByNames to retrieve URL from list of page names/path arguments diff -r 66a050b32df8 -r 4ba7df23b976 src/server/pages.py --- a/src/server/pages.py Mon Jan 22 22:16:07 2018 +0100 +++ b/src/server/pages.py Mon Jan 22 22:17:20 2018 +0100 @@ -489,6 +489,28 @@ path, child = self.getSubPageByName(self, page_name) return os.path.join(u'/', current_url, path, *[quote(a) for a in args]) + def getURLByNames(self, named_path): + """retrieve URL from pages names and arguments + + @param named_path(list[tuple[unicode, list[unicode]]]): path to the page as a list + of tuples of 2 items: + - first item is page name + - second item is list of path arguments of this page + @return (unicode): URL to the requested page with given path arguments + @raise exceptions.NotFound: one of the page was not found + """ + current_page = None + path = [] + for page_name, page_args in named_path: + if current_page is None: + current_page = self.getPageByName(page_name) + path.append(current_page.getURL(*page_args)) + else: + sub_path, current_page = self.getSubPageByName(current_page, page_name) + path.append(sub_path) + if page_args: + path.extend([quote(a) for a in page_args]) + return u'/'.join(path) def getChildWithDefault(self, path, request): # we handle children ourselves