|
6 | 6 | """
|
7 | 7 | from __future__ import unicode_literals
|
8 | 8 |
|
9 |
| -from django.http import Http404 |
10 | 9 | from rest_framework import status
|
11 | 10 | from rest_framework.response import Response
|
12 |
| -from rest_framework.request import clone_request |
13 | 11 | from rest_framework.settings import api_settings
|
14 | 12 |
|
15 | 13 |
|
@@ -89,49 +87,3 @@ def destroy(self, request, *args, **kwargs):
|
89 | 87 |
|
90 | 88 | def perform_destroy(self, instance):
|
91 | 89 | instance.delete()
|
92 |
| - |
93 |
| - |
94 |
| -# The AllowPUTAsCreateMixin was previously the default behaviour |
95 |
| -# for PUT requests. This has now been removed and must be *explicitly* |
96 |
| -# included if it is the behavior that you want. |
97 |
| -# For more info see: ... |
98 |
| - |
99 |
| -class AllowPUTAsCreateMixin(object): |
100 |
| - """ |
101 |
| - The following mixin class may be used in order to support PUT-as-create |
102 |
| - behavior for incoming requests. |
103 |
| - """ |
104 |
| - def update(self, request, *args, **kwargs): |
105 |
| - partial = kwargs.pop('partial', False) |
106 |
| - instance = self.get_object_or_none() |
107 |
| - serializer = self.get_serializer(instance, data=request.data, partial=partial) |
108 |
| - serializer.is_valid(raise_exception=True) |
109 |
| - |
110 |
| - if instance is None: |
111 |
| - lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field |
112 |
| - lookup_value = self.kwargs[lookup_url_kwarg] |
113 |
| - extra_kwargs = {self.lookup_field: lookup_value} |
114 |
| - serializer.save(**extra_kwargs) |
115 |
| - return Response(serializer.data, status=status.HTTP_201_CREATED) |
116 |
| - |
117 |
| - serializer.save() |
118 |
| - return Response(serializer.data) |
119 |
| - |
120 |
| - def partial_update(self, request, *args, **kwargs): |
121 |
| - kwargs['partial'] = True |
122 |
| - return self.update(request, *args, **kwargs) |
123 |
| - |
124 |
| - def get_object_or_none(self): |
125 |
| - try: |
126 |
| - return self.get_object() |
127 |
| - except Http404: |
128 |
| - if self.request.method == 'PUT': |
129 |
| - # For PUT-as-create operation, we need to ensure that we have |
130 |
| - # relevant permissions, as if this was a POST request. This |
131 |
| - # will either raise a PermissionDenied exception, or simply |
132 |
| - # return None. |
133 |
| - self.check_permissions(clone_request(self.request, 'POST')) |
134 |
| - else: |
135 |
| - # PATCH requests where the object does not exist should still |
136 |
| - # return a 404 response. |
137 |
| - raise |
0 commit comments