tomchristie/django-rest-framework — Issue #158: Streamline and unmagicify view.DATA / view.CONTENT
Author: flashingpumpkin
Created: 2012-02-10 11:22:06+00:00
State: open

Hi

I find it awkward that the `DATA` attribute on views does not provide a consistent interface to request data, both in the request body and as url query params.

Sample code:

```python

class OAuth2Authentication(BaseAuthentication):
def authenticate(self, request):
if request.method.lower() in ["get", "delete"]:
form = OAuthTokenForm(request.GET)
else:
form = OAuthTokenForm(self.view.DATA)
if form.is_valid():
return form.cleaned_data.get('oauth_token').user

```

Even though it is discouraged in the Django core, I'd much rather have something along the lines of [the REQUEST attribute](https://docs.djangoproject.com/en/1.3/ref/request-response/#django.http.HttpRequest.REQUEST) that consistantly returns all the data, no matter from where. The [current DATA documentation](http://django-rest-framework.org/library/mixins.html?highlight=data#mixins.RequestMixin.DATA) is misleading in that it suggests that it will also return GET and DELETE data, which is not the case.

Also - I find it awkward that `DATA` and `CONTENT` are properties and would strongly prefer methods like the following on the views:

```python

def get_(raw_)data(self):
""" Returns uncleaned data straight from the parser """

def clean / is_valid / full_clean / clean_data(self):
""" Basically mimic the form api to clean the raw data and create a `cleaned_data` attribute """

```

Maybe something to think about while @sebpiq is doing all of the backwards incompatible refactoring work on his mainline.

You'll lose one or two more lines of code to the views dealing with data but gain explicity.