feat: add util.get_form_data()
convenience function
This commit is contained in:
parent
26d44390a5
commit
3b6b317377
2 changed files with 49 additions and 1 deletions
|
@ -21,12 +21,33 @@
|
|||
#
|
||||
################################################################################
|
||||
"""
|
||||
Utilities
|
||||
Web Utilities
|
||||
"""
|
||||
|
||||
import importlib
|
||||
|
||||
|
||||
def get_form_data(request):
|
||||
"""
|
||||
Returns the effective form data for the given request.
|
||||
|
||||
Mostly this is a convenience, which simply returns one of the
|
||||
following, depending on various attributes of the request.
|
||||
|
||||
* :attr:`pyramid:pyramid.request.Request.POST`
|
||||
* :attr:`pyramid:pyramid.request.Request.json_body`
|
||||
"""
|
||||
# nb. we prefer JSON only if no POST is present
|
||||
# TODO: this seems to work for our use case at least, but perhaps
|
||||
# there is a better way? see also
|
||||
# https://docs.pylonsproject.org/projects/pyramid/en/latest/api/request.html#pyramid.request.Request.is_xhr
|
||||
if not request.POST and (
|
||||
getattr(request, 'is_xhr', False)
|
||||
or request.content_type == 'application/json'):
|
||||
return request.json_body
|
||||
return request.POST
|
||||
|
||||
|
||||
def get_libver(
|
||||
request,
|
||||
key,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue