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
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)
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 )
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({})
def perform_create(self, serializer): r = super().perform_create(serializer) record.send(serializer.instance) return r