Example #1
0
 def perform_create(self, serializer):
     r = super().perform_create(serializer)
     plugins.trigger_hook(
         plugins.LISTENING_CREATED,
         listening=serializer.instance,
         confs=plugins.get_confs(self.request.user),
     )
     record.send(serializer.instance)
     return r
Example #2
0
def test_record_object_calls_consumer(activity_registry, mocker):
    activity_registry.register_serializer(FakeSerializer)
    stub = mocker.stub()
    activity_registry.register_consumer("tests.FakeModel")(stub)
    o = FakeModel(id=1)
    data = FakeSerializer(o).data
    record.send(o)

    stub.assert_called_once_with(data=data, obj=o)
Example #3
0
 def create(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     instance = self.perform_create(serializer)
     serializer = self.get_serializer(instance=instance)
     headers = self.get_success_headers(serializer.data)
     record.send(instance)
     return Response(
         serializer.data, status=status.HTTP_201_CREATED, headers=headers
     )
Example #4
0
 def scrobble(self, request, *args, **kwargs):
     data = request.GET or request.POST
     serializer = serializers.ScrobbleSerializer(
         data=data, context={"user": request.user})
     if not serializer.is_valid():
         return response.Response(
             {"error": {
                 "code": 0,
                 "message": "Invalid payload"
             }})
     if serializer.validated_data["submission"]:
         listening = serializer.save()
         record.send(listening)
     return response.Response({})
Example #5
0
 def perform_create(self, serializer):
     r = super().perform_create(serializer)
     record.send(serializer.instance)
     return r