diff options
| author | Tom Christie | 2014-11-03 12:00:19 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-11-03 12:00:19 +0000 | 
| commit | d27b8cc09b83bac10346effa1021493d2835b794 (patch) | |
| tree | d9e7ff7ee173c1844734f16d0bf6fa2055088076 /rest_framework/mixins.py | |
| parent | 37845968cd66e6372bbc22fd3ced131dff3b824a (diff) | |
| download | django-rest-framework-d27b8cc09b83bac10346effa1021493d2835b794.tar.bz2 | |
PUT as create docs, and move mixin out to external gist
Diffstat (limited to 'rest_framework/mixins.py')
| -rw-r--r-- | rest_framework/mixins.py | 48 | 
1 files changed, 0 insertions, 48 deletions
| diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 467ff515..2074a107 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -6,10 +6,8 @@ which allows mixin classes to be composed in interesting ways.  """  from __future__ import unicode_literals -from django.http import Http404  from rest_framework import status  from rest_framework.response import Response -from rest_framework.request import clone_request  from rest_framework.settings import api_settings @@ -89,49 +87,3 @@ class DestroyModelMixin(object):      def perform_destroy(self, instance):          instance.delete() - - -# The AllowPUTAsCreateMixin was previously the default behaviour -# for PUT requests. This has now been removed and must be *explicitly* -# included if it is the behavior that you want. -# For more info see: ... - -class AllowPUTAsCreateMixin(object): -    """ -    The following mixin class may be used in order to support PUT-as-create -    behavior for incoming requests. -    """ -    def update(self, request, *args, **kwargs): -        partial = kwargs.pop('partial', False) -        instance = self.get_object_or_none() -        serializer = self.get_serializer(instance, data=request.data, partial=partial) -        serializer.is_valid(raise_exception=True) - -        if instance is None: -            lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field -            lookup_value = self.kwargs[lookup_url_kwarg] -            extra_kwargs = {self.lookup_field: lookup_value} -            serializer.save(**extra_kwargs) -            return Response(serializer.data, status=status.HTTP_201_CREATED) - -        serializer.save() -        return Response(serializer.data) - -    def partial_update(self, request, *args, **kwargs): -        kwargs['partial'] = True -        return self.update(request, *args, **kwargs) - -    def get_object_or_none(self): -        try: -            return self.get_object() -        except Http404: -            if self.request.method == 'PUT': -                # For PUT-as-create operation, we need to ensure that we have -                # relevant permissions, as if this was a POST request.  This -                # will either raise a PermissionDenied exception, or simply -                # return None. -                self.check_permissions(clone_request(self.request, 'POST')) -            else: -                # PATCH requests where the object does not exist should still -                # return a 404 response. -                raise | 
