Exemple #1
0
 def list(self, request):
     queryset = self.get_queryset()
     page = self.paginate_queryset(queryset)
     if page is not None:
         serializer = serializers.NotificationSerializer(
             page, context={'request': request}, many=True)
         return self.get_paginated_response(serializer.data)
     serializer = serializers.NotificationSerializer(
         queryset, context={'request': request}, many=True)
     return Response(serializer.data)
Exemple #2
0
 def list(self, request):
     queryset = self.get_queryset()
     if queryset is None:
         return Response({'detail': 'Permission Denied'}, status=status.HTTP_403_FORBIDDEN)
     page = self.paginate_queryset(queryset)
     if page is not None:
         serializer = serializers.NotificationSerializer(page,
             context={'request': request}, many=True)
         return self.get_paginated_response(serializer.data)
     serializer = serializers.NotificationSerializer(queryset,
         context={'request': request}, many=True)
     return Response(serializer.data)
Exemple #3
0
    def create(self, request):
        serializer = serializers.NotificationSerializer(data=request.data,
            context={'request': request}, partial=True)

        if not serializer.is_valid():
            logger.error('{0!s}'.format(serializer.errors))
            raise errors.ValidationException('{0!s}'.format(serializer.errors))

        serializer.save()

        return Response(serializer.data, status=status.HTTP_201_CREATED)
Exemple #4
0
    def update(self, request, pk=None):
        """
        Update is used only change the expiration date of the message
        """
        instance = self.get_queryset().get(pk=pk)
        serializer = serializers.NotificationSerializer(instance,
            data=request.data, context={'request': request}, partial=True)

        if not serializer.is_valid():
            logger.error('{0!s}'.format(serializer.errors))
            raise errors.ValidationException('{0!s}'.format(serializer.errors))

        serializer.save()

        return Response(serializer.data, status=status.HTTP_200_OK)