#126 closed defect (fixed)
Patch to place the post_data into the request variable
Reported by: | anonymous | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This is a patch to put the post_data into the request variable. This is helpful for views that need access to the raw data.
Index: wsgi.py =================================================================== --- wsgi.py (revision 256) +++ wsgi.py (working copy) @@ -20,6 +20,7 @@ # Populates self._post and self._files if self.environ['REQUEST_METHOD'] == 'POST': post_data = self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"])) + self._post_data = post_data if self.environ.get('CONTENT_TYPE', '').startswith('multipart'): header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')]) self._post, self._files = httpwrappers.parse_file_upload(header_dict, post_data) @@ -89,7 +90,18 @@ def _set_user(self, user): self._user = user + + def _set_post_data(self,post_data): + self._post_data = post_data + def _get_post_data(self): + if not hasattr(self, '_post_data'): + self._load_post_and_files() + if hasattr(self, '_post_data'): + return(self._post_data) + else: + return("") + GET = property(_get_get, _set_get) POST = property(_get_post, _set_post) COOKIES = property(_get_cookies, _set_cookies) @@ -97,6 +109,7 @@ REQUEST = property(_get_request) session = property(_get_session, _set_session) user = property(_get_user, _set_user) + post_data = property(_get_post_data,_set_post_data) class WSGIHandler: def __init__(self): Index: modpython.py =================================================================== --- modpython.py (revision 256) +++ modpython.py (working copy) @@ -21,10 +21,11 @@ def _load_post_and_files(self): "Populates self._post and self._files" + self._post_data = self._req.read() if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'): - self._post, self._files = httpwrappers.parse_file_upload(self._req.headers_in, self._req.read()) + self._post, self._files = httpwrappers.parse_file_upload(self._req.headers_in, self._post_data) else: - self._post, self._files = httpwrappers.QueryDict(self._req.read()), datastructures.MultiValueDict() + self._post, self._files = httpwrappers.QueryDict(self._post_data), datastructures.MultiValueDict() def _get_request(self): if not hasattr(self, '_request'): @@ -115,6 +116,18 @@ def _set_user(self, user): self._user = user + def _set_post_data(self,post_data): + self._post_data = post_data + + def _get_post_data(self): + if not hasattr(self, '_post_data'): + self._load_post_and_files() + if hasattr(self, '_post_data'): + return(self._post_data) + else: + return("") + + GET = property(_get_get, _set_get) POST = property(_get_post, _set_post) COOKIES = property(_get_cookies, _set_cookies) @@ -123,7 +136,8 @@ REQUEST = property(_get_request) session = property(_get_session, _set_session) user = property(_get_user, _set_user) - + post_data = property(_get_post_data,_set_post_data) + class ModPythonHandler: def __init__(self): self._request_middleware = self._view_middleware = self._response_middleware = None
Attachments (1)
Change History (3)
by , 19 years ago
Attachment: | post_data.patch added |
---|
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [478]) Fixed #126 -- HttpRequest now has a 'raw_post_data' attribute.
Note:
See TracTickets
for help on using tickets.
This could use some comments.