aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2020-04-08 23:13:20 +0100
committerStephen Finucane <stephen@that.guru>2020-04-08 23:35:17 +0100
commit600f54b56ac1a43d0df494e3b30a3826af553a41 (patch)
tree244f533720912dc79f47ec93b4eda4c502b9049b
parentd3d4f9f36b2b16aa54837b67733f2de5cf93457b (diff)
downloadpatchwork-600f54b56ac1a43d0df494e3b30a3826af553a41.tar
patchwork-600f54b56ac1a43d0df494e3b30a3826af553a41.tar.gz
REST: Resolve warnings with DRF >= 3.11
Signed-off-by: Stephen Finucane <stephen@that.guru>
-rw-r--r--patchwork/api/check.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/patchwork/api/check.py b/patchwork/api/check.py
index 07d7cb9..a6bf5f8 100644
--- a/patchwork/api/check.py
+++ b/patchwork/api/check.py
@@ -6,6 +6,7 @@
from django.http import Http404
from django.http.request import QueryDict
from django.shortcuts import get_object_or_404
+import rest_framework
from rest_framework.exceptions import PermissionDenied
from rest_framework.generics import ListCreateAPIView
from rest_framework.generics import RetrieveAPIView
@@ -22,12 +23,22 @@ from patchwork.models import Check
from patchwork.models import Patch
-class CurrentPatchDefault(object):
- def set_context(self, serializer_field):
- self.patch = serializer_field.context['request'].patch
+DRF_VERSION = tuple(int(x) for x in rest_framework.__version__.split('.'))
- def __call__(self):
- return self.patch
+
+if DRF_VERSION > (3, 11):
+ class CurrentPatchDefault(object):
+ requires_context = True
+
+ def __call__(self, serializer_field):
+ return serializer_field.context['request'].patch
+else:
+ class CurrentPatchDefault(object):
+ def set_context(self, serializer_field):
+ self.patch = serializer_field.context['request'].patch
+
+ def __call__(self):
+ return self.patch
class CheckSerializer(HyperlinkedModelSerializer):