comparison src/server/pages.py @ 1032:863cc6f97068

pages: path arguments can now be specified in pageRedirect
author Goffi <goffi@goffi.org>
date Mon, 22 Jan 2018 22:18:47 +0100
parents 4ba7df23b976
children c34f08e05cdf
comparison
equal deleted inserted replaced
1031:4ba7df23b976 1032:863cc6f97068
725 # we only want local urls 725 # we only want local urls
726 self.pageError(request, C.HTTP_BAD_REQUEST) 726 self.pageError(request, C.HTTP_BAD_REQUEST)
727 else: 727 else:
728 self.HTTPRedirect(request, url) 728 self.HTTPRedirect(request, url)
729 729
730 def pageRedirect(self, page_path, request, skip_parse_url=True): 730 def pageRedirect(self, page_path, request, skip_parse_url=True, path_args=None):
731 """redirect a page to a named page 731 """redirect a page to a named page
732 732
733 the workflow will continue with the workflow of the named page, 733 the workflow will continue with the workflow of the named page,
734 skipping named page's parse_url method if it exist. 734 skipping named page's parse_url method if it exist.
735 If you want to do a HTTP redirection, use HTTPRedirect 735 If you want to do a HTTP redirection, use HTTPRedirect
742 e.g.: "blog" redirect to page named "blog" 742 e.g.: "blog" redirect to page named "blog"
743 "blog/atom.xml" redirect to atom.xml subpage of "blog" 743 "blog/atom.xml" redirect to atom.xml subpage of "blog"
744 "/common/blog/atom.xml" redirect to the page at the fiven full path 744 "/common/blog/atom.xml" redirect to the page at the fiven full path
745 @param request(server.Request): current HTTP request 745 @param request(server.Request): current HTTP request
746 @param skip_parse_url(bool): if True, parse_url method on redirect page will be skipped 746 @param skip_parse_url(bool): if True, parse_url method on redirect page will be skipped
747 @param path_args(list[unicode], None): path arguments to use in redirected page
747 @raise KeyError: there is no known page with this name 748 @raise KeyError: there is no known page with this name
748 """ 749 """
749 # FIXME: render non LiberviaPage resources 750 # FIXME: render non LiberviaPage resources
750 path = page_path.rstrip(u'/').split(u'/') 751 path = page_path.rstrip(u'/').split(u'/')
751 if not path[0]: 752 if not path[0]:
756 for subpage in path[1:]: 757 for subpage in path[1:]:
757 if redirect_page is self.host.root: 758 if redirect_page is self.host.root:
758 redirect_page = redirect_page.children[subpage] 759 redirect_page = redirect_page.children[subpage]
759 else: 760 else:
760 redirect_page = redirect_page.original.children[subpage] 761 redirect_page = redirect_page.original.children[subpage]
762
763 if path_args is not None:
764 args = [quote(a) for a in path_args]
765 request.postpath = args + request.postpath
761 766
762 redirect_page.renderPage(request, skip_parse_url=skip_parse_url) 767 redirect_page.renderPage(request, skip_parse_url=skip_parse_url)
763 raise failure.Failure(exceptions.CancelError(u'page redirection is used')) 768 raise failure.Failure(exceptions.CancelError(u'page redirection is used'))
764 769
765 def pageError(self, request, code=C.HTTP_NOT_FOUND, no_body=False): 770 def pageError(self, request, code=C.HTTP_NOT_FOUND, no_body=False):