# HG changeset patch # User Goffi # Date 1516655767 -3600 # Node ID 66a050b32df8603b4eb64809562d00516b32233c # Parent 78b7b5ec7ca1c4ffd948388c890ed5cc09c97ec5 pages: moved code getting subpage from getSubPageURL to new getSubPageByName method. diff -r 78b7b5ec7ca1 -r 66a050b32df8 src/server/pages.py --- a/src/server/pages.py Mon Jan 22 08:53:06 2018 +0100 +++ b/src/server/pages.py Mon Jan 22 22:16:07 2018 +0100 @@ -447,6 +447,25 @@ current_url = current_url + u'?' + encoded return current_url + def getSubPageByName(self, page, subpage_name): + """retrieve a subpage and its path using its name + + @param request(server.Request): current HTTP request + @param page_name(unicode): name of the page to retrieve + it must be a direct children of current page + @return (tuple[str, LiberviaPage]): page subpath and instance + @raise exceptions.NotFound: no page has been found + """ + for path, child in page.children.iteritems(): + try: + child_name = child.name + except AttributeError: + # LiberviaPages have a name, but maybe this is an other Resource + continue + if child_name == subpage_name: + return path, child + raise exceptions.NotFound(_(u'requested sub page has not been found')) + def getSubPageURL(self, request, page_name, *args): """retrieve a page in direct children and build its URL according to request @@ -467,16 +486,9 @@ @return unicode: absolute URL to the sub page """ current_url = self.getCurrentURL(request) + path, child = self.getSubPageByName(self, page_name) + return os.path.join(u'/', current_url, path, *[quote(a) for a in args]) - for path, child in self.children.iteritems(): - try: - child_name = child.name - except AttributeError: - # LiberviaPage have a name, but maybe this is an other Resource - continue - if child_name == page_name: - return os.path.join(u'/', current_url, path, *args) - raise exceptions.NotFound(_(u'requested sub page has not been found')) def getChildWithDefault(self, path, request): # we handle children ourselves