Mercurial > libervia-web
comparison src/server/server.py @ 968:4d37b23777c3
pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
instead of giving a full uri, a page is now given when we want to redirect to something else that current page on data post.
This make the redirection more simple and intuive
A tuple can be used to specify arguments to put in URL.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 09 Nov 2017 08:02:47 +0100 |
parents | 12c149171199 |
children | c4e58c4dba75 |
comparison
equal
deleted
inserted
replaced
967:4d1dcf97740f | 968:4d37b23777c3 |
---|---|
1656 url = request.URLPath(), | 1656 url = request.URLPath(), |
1657 msg = failure_)) | 1657 msg = failure_)) |
1658 self.pageError(request, C.HTTP_INTERNAL_ERROR) | 1658 self.pageError(request, C.HTTP_INTERNAL_ERROR) |
1659 | 1659 |
1660 def _on_data_post_redirect(self, ret, request): | 1660 def _on_data_post_redirect(self, ret, request): |
1661 """called when page's on_data_post has been called successfuly | 1661 """called when page's on_data_post has been done successfuly |
1662 | 1662 |
1663 this method redirect to the same page or to request.data['post_redirect_uri'] | 1663 This will do a Post/Redirect/Get pattern. |
1664 if it is set, using Post/Redirect/Get pattern. | 1664 this method redirect to the same page or to request.data['post_redirect_page'] |
1665 HTTP status code "See Other" (303) is the recommanded code in this case | 1665 post_redirect_page can be either a page or a tuple with page as first item, then a list of unicode arguments to append to the url. |
1666 if post_redirect_page is not used, initial request.uri (i.e. the same page as where the data have been posted) will be used for redirection. | |
1667 HTTP status code "See Other" (303) is used as it is the recommanded code in this case. | |
1666 @param ret(None, unicode, iterable): on_data_post return value | 1668 @param ret(None, unicode, iterable): on_data_post return value |
1667 see LiberviaPage.__init__ on_data_post docstring | 1669 see LiberviaPage.__init__ on_data_post docstring |
1668 """ | 1670 """ |
1669 if ret is None: | 1671 if ret is None: |
1670 ret = () | 1672 ret = () |
1672 ret = (ret,) | 1674 ret = (ret,) |
1673 else: | 1675 else: |
1674 ret = tuple(ret) | 1676 ret = tuple(ret) |
1675 raise NotImplementedError(_(u'iterable in on_data_post return value is not used yet')) | 1677 raise NotImplementedError(_(u'iterable in on_data_post return value is not used yet')) |
1676 session_data = self.host.getSessionData(request, session_iface.ISATSession) | 1678 session_data = self.host.getSessionData(request, session_iface.ISATSession) |
1679 if 'post_redirect_page' in request.data: | |
1680 redirect_page_data = request.data['post_redirect_page'] | |
1681 if isinstance(redirect_page_data, tuple): | |
1682 redirect_page = redirect_page_data[0] | |
1683 redirect_page_args = [urllib.quote_plus(a.encode('utf-8')).replace('%40','@') | |
1684 for a in redirect_page_data[1:]] | |
1685 else: | |
1686 redirect_page = redirect_page_data | |
1687 redirect_page_args = [] | |
1688 redirect_uri = os.path.join(redirect_page.url, *redirect_page_args) | |
1689 else: | |
1690 redirect_page = self | |
1691 redirect_uri = request.uri | |
1692 | |
1677 if not C.POST_NO_CONFIRM in ret: | 1693 if not C.POST_NO_CONFIRM in ret: |
1678 session_data.setPageFlag(self, C.FLAG_CONFIRM) | 1694 session_data.setPageFlag(redirect_page, C.FLAG_CONFIRM) |
1679 request.setResponseCode(C.HTTP_SEE_OTHER) | 1695 request.setResponseCode(C.HTTP_SEE_OTHER) |
1680 request.setHeader("location", request.data.get('post_redirect_uri', request.uri)) | 1696 request.setHeader("location", redirect_uri) |
1681 request.finish() | 1697 request.finish() |
1682 raise failure.Failure(exceptions.CancelError(u'Post/Redirect/Get is used')) | 1698 raise failure.Failure(exceptions.CancelError(u'Post/Redirect/Get is used')) |
1683 | 1699 |
1684 def _on_data_post(self, dummy, request): | 1700 def _on_data_post(self, dummy, request): |
1685 csrf_token = self.host.getSessionData(request, session_iface.ISATSession).csrf_token | 1701 csrf_token = self.host.getSessionData(request, session_iface.ISATSession).csrf_token |