diff --git a/program/views.py b/program/views.py index 78be1f363f2b64718c0ddad005c7e8faa6d2e6fe..0336d507f0773f4b6509ec71b30c943f9e07eadb 100644 --- a/program/views.py +++ b/program/views.py @@ -293,7 +293,9 @@ class APIShowViewSet(DisabledObjectPermissionCheckMixin, viewsets.ModelViewSet): if not request.user.is_superuser: return Response(status=status.HTTP_401_UNAUTHORIZED) - serializer = ShowSerializer(data=request.data) + serializer = ShowSerializer( + data=request.data, context={"created_by": request.user.username} + ) if serializer.is_valid(): serializer.save() @@ -315,7 +317,7 @@ class APIShowViewSet(DisabledObjectPermissionCheckMixin, viewsets.ModelViewSet): show = self.get_object() serializer = ShowSerializer( - show, data=request.data, context={"user": request.user} + show, data=request.data, context={"updated_by": request.user.username} ) if serializer.is_valid(): @@ -667,7 +669,7 @@ class APINoteViewSet( serializer = NoteSerializer( data={"show": show_pk, "timeslot": timeslot_pk} | request.data, - context={"user_id": request.user.id}, + context={"created_by": request.user.username}, ) if serializer.is_valid(): @@ -695,7 +697,9 @@ class APINoteViewSet( return Response(status=status.HTTP_401_UNAUTHORIZED) note = self.get_object() - serializer = NoteSerializer(note, data=request.data) + serializer = NoteSerializer( + note, data=request.data, context={"updated_by": request.user.username} + ) if serializer.is_valid(): hosts = Host.objects.filter( @@ -825,3 +829,23 @@ class APIHostViewSet(ActiveFilterMixin, viewsets.ModelViewSet): queryset = Host.objects.all() serializer_class = HostSerializer pagination_class = LimitOffsetPagination + + def create(self, request, *args, **kwargs): + serializer = HostSerializer( + data=request.data, context={"created_by": request.user.username} + ) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) + else: + Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + def update(self, request, *args, **kwargs): + serializer = HostSerializer( + data=request.data, context={"updated_by": request.user.username} + ) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) + else: + Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)