Skip to content

Streamline and unmagicify view.DATA / view.CONTENT #158

Closed
@flashingpumpkin

Description

@flashingpumpkin

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:

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 that consistantly returns all the data, no matter from where. The current DATA documentation 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:

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 explicitness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions