aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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):