comparison libervia/server/pages.py @ 1284:65c43eec15ad

pages: `on_data_post` can be set to the string `continue` instead of a callable: if `on_data_post` == "continue", then request won't be stopped if `POST` method is used, and `render` method can be used to handle it.
author Goffi <goffi@goffi.org>
date Fri, 19 Jun 2020 16:47:51 +0200
parents 436ef2ad92af
children 37a582b0fe53
comparison
equal deleted inserted replaced
1283:436ef2ad92af 1284:65c43eec15ad
158 string. 158 string.
159 @param template(unicode, None): path to the template to render. 159 @param template(unicode, None): path to the template to render.
160 This method is mutually exclusive with render 160 This method is mutually exclusive with render
161 @param on_data_post(callable, None): method to call when data is posted 161 @param on_data_post(callable, None): method to call when data is posted
162 None if data post is not handled 162 None if data post is not handled
163 on_data_post can return a string with following value: 163 "continue" if data post is not handled there, and we must not interrupt
164 workflow (i.e. it's handled in "render" method).
165 otherwise, on_data_post can return a string with following value:
164 - C.POST_NO_CONFIRM: confirm flag will not be set 166 - C.POST_NO_CONFIRM: confirm flag will not be set
165 on_data_post can raise following exceptions: 167 on_data_post can raise following exceptions:
166 - exceptions.DataError: value is incorrect, message will be displayed 168 - exceptions.DataError: value is incorrect, message will be displayed
167 as a notification 169 as a notification
168 @param on_data(callable, None): method to call when dynamic data is sent 170 @param on_data(callable, None): method to call when dynamic data is sent
1678 log.warning(_( 1680 log.warning(_(
1679 "Theme {theme!r} doesn't exist for {vhost}" 1681 "Theme {theme!r} doesn't exist for {vhost}"
1680 .format(theme=theme, vhost=self.vhost_root))) 1682 .format(theme=theme, vhost=self.vhost_root)))
1681 else: 1683 else:
1682 session_data.theme = theme 1684 session_data.theme = theme
1683
1684
1685 try: 1685 try:
1686 1686
1687 try: 1687 try:
1688 self._checkAccess(request) 1688 self._checkAccess(request)
1689 1689
1711 if request.method not in (C.HTTP_METHOD_GET, C.HTTP_METHOD_POST): 1711 if request.method not in (C.HTTP_METHOD_GET, C.HTTP_METHOD_POST):
1712 # only HTTP GET and POST are handled so far 1712 # only HTTP GET and POST are handled so far
1713 self.pageError(request, C.HTTP_BAD_REQUEST) 1713 self.pageError(request, C.HTTP_BAD_REQUEST)
1714 1714
1715 if request.method == C.HTTP_METHOD_POST: 1715 if request.method == C.HTTP_METHOD_POST:
1716 if self.on_data_post is None: 1716 if self.on_data_post == 'continue':
1717 pass
1718 elif self.on_data_post is None:
1717 # if we don't have on_data_post, the page was not expecting POST 1719 # if we don't have on_data_post, the page was not expecting POST
1718 # so we return an error 1720 # so we return an error
1719 self.pageError(request, C.HTTP_BAD_REQUEST) 1721 self.pageError(request, C.HTTP_BAD_REQUEST)
1720 else: 1722 else:
1721 await self._on_data_post(request) 1723 await self._on_data_post(request)