From d587ad10210299f9c22ae2b46af2f09215feb4bf Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 4 Nov 2015 14:10:51 +0000 Subject: [PATCH] Use REST framework request parsing when accessing old-style .POST --- rest_framework/authentication.py | 5 ++--- rest_framework/request.py | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index da88a239b..9e73ef632 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -117,9 +117,8 @@ class SessionAuthentication(BaseAuthentication): Otherwise returns `None`. """ - # Get the underlying HttpRequest object - request = request._request - user = getattr(request, 'user', None) + # Get the session-based user from the underlying HttpRequest object + user = getattr(request._request, 'user', None) # Unauthenticated, CSRF validation not required if not user or not user.is_active: diff --git a/rest_framework/request.py b/rest_framework/request.py index 76bf496ce..846cadcd9 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -365,6 +365,15 @@ class Request(object): 'since version 3.0, and has been fully removed as of version 3.2.' ) + @property + def POST(self): + # Ensure that request.POST uses our request parsing. + if not _hasattr(self, '_data'): + self._load_data_and_files() + if is_form_media_type(self.content_type): + return self.data + return QueryDict('', encoding=self._request._encoding) + @property def FILES(self): # Leave this one alone for backwards compat with Django's request.FILES