Skip to content
Snippets Groups Projects
Verified Commit de317bac authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

fix: properly inject the request into the serializer context

parent e57f5f2e
No related branches found
No related tags found
No related merge requests found
......@@ -577,10 +577,14 @@ class APIUserViewSet(
else:
return User.objects.filter(pk=user.id)
def get_serializer_context(self):
context = super().get_serializer_context()
context.update({"request": self.request})
return context
def create(self, request, *args, **kwargs):
serializer = UserSerializer(
# FIXME: the method get_serializer_context should be used but it does seem to get lost
context={"request": request}, # the serializer needs the request in the context
data=request.data,
)
......@@ -710,10 +714,14 @@ class APIShowViewSet(viewsets.ModelViewSet):
self.check_object_permissions(self.request, obj)
return obj
def get_serializer_context(self):
context = super().get_serializer_context()
context.update({"request": self.request})
return context
def create(self, request, *args, **kwargs):
serializer = ShowSerializer(
# FIXME: the method get_serializer_context should be used but it does seem to get lost
context={"request": request}, # the serializer needs the request in the context
data=request.data,
)
......@@ -733,8 +741,6 @@ class APIShowViewSet(viewsets.ModelViewSet):
partial = kwargs.get("partial", False)
show = self.get_object()
serializer = ShowSerializer(
# FIXME: the method get_serializer_context should be used but it does seem to get lost
context={"request": request}, # the serializer needs the request in the context
data=request.data,
instance=show,
partial=partial,
......@@ -1329,6 +1335,12 @@ class APITimeSlotViewSet(
queryset = TimeSlot.objects.all().order_by("-start")
serializer_class = TimeSlotSerializer
def get_serializer_context(self):
context = super().get_serializer_context()
context.update({"request": self.request})
return context
def update(self, request, *args, **kwargs):
show_pk = get_values(self.kwargs, "show_pk")
timeslot = self.get_object()
......@@ -1482,10 +1494,14 @@ class APIProfileViewSet(ActiveFilterMixin, viewsets.ModelViewSet):
filter_backends = [drf_filters.SearchFilter]
search_fields = ["name", "email"]
def get_serializer_context(self):
context = super().get_serializer_context()
context.update({"request": self.request})
return context
def create(self, request, *args, **kwargs):
serializer = ProfileSerializer(
# FIXME: the method get_serializer_context should be used but it does seem to get lost
context={"request": request}, # the serializer needs the request in the context
data=request.data,
)
if serializer.is_valid(raise_exception=True):
......@@ -1497,8 +1513,6 @@ class APIProfileViewSet(ActiveFilterMixin, viewsets.ModelViewSet):
profile = self.get_object()
serializer = ProfileSerializer(
# FIXME: the method get_serializer_context should be used but it does seem to get lost
context={"request": request}, # the serializer needs the request in the context
data=request.data,
instance=profile,
partial=partial,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment