Exemple #1
0
class SimpleActivitySerializer(serializers.ModelSerializer):
    action = serializers.CharField(source='verb')
    activity_type = serializers.SerializerMethodField()
    activity = GenericRelatedField(
        {
            get_user_model(): SimpleUserSerializer(),
            Channel: ChannelSerializer(),
            ChannelUser: ChannelUserSerializer(),
            Message: MessageSerializer(),
            Comment: CommentSerializer(),
            Upload: UploadSerializer(),
            Connection: ConnectionSerializer(),
            Task: SimpleTaskSerializer(),
            Application: ApplicationSerializer(),
            Participation: ParticipationSerializer(),
            Estimate: SimpleEstimateSerializer(),
            Quote: SimpleQuoteSerializer(),
            ProgressEvent: SimpleProgressEventSerializer(),
            ProgressReport: ProgressReportSerializer(),
            Integration: SimpleIntegrationSerializer(),
            IntegrationActivity: SimpleIntegrationActivitySerializer()
        },
        source='action_object')

    class Meta:
        model = Action
        exclude = ('verb', 'actor_object_id', 'actor_content_type',
                   'action_object_object_id', 'action_object_content_type',
                   'target_object_id', 'target_content_type')

    def get_activity_type(self, obj):
        return get_instance_type(obj.action_object)
class ActivitySerializer(SimpleActivitySerializer):
    actor_type = serializers.SerializerMethodField()
    target_type = serializers.SerializerMethodField()
    actor = GenericRelatedField({
        get_user_model(): SimpleUserSerializer(),
        Integration: SimpleIntegrationSerializer()
    })
    target = GenericRelatedField({
        get_user_model():
        SimpleUserSerializer(),
        Channel:
        ChannelSerializer(),
        ChannelUser:
        ChannelUserSerializer(),
        Message:
        MessageSerializer(),
        Comment:
        CommentSerializer(),
        Upload:
        UploadSerializer(),
        Connection:
        ConnectionSerializer(),
        Task:
        SimpleTaskSerializer(),
        Application:
        ApplicationSerializer(),
        Participation:
        ParticipationSerializer(),
        ProgressEvent:
        SimpleProgressEventSerializer(),
        ProgressReport:
        SimpleProgressReportSerializer(),
        Integration:
        SimpleIntegrationSerializer(),
        IntegrationActivity:
        SimpleIntegrationActivitySerializer()
    })

    class Meta(SimpleActivitySerializer.Meta):
        fields = '__all__'
        exclude = None

    def get_actor_type(self, obj):
        return get_instance_type(obj.actor)

    def get_target_type(self, obj):
        return get_instance_type(obj.target)
Exemple #3
0
class ActivitySerializer(SimpleActivitySerializer):
    actor_type = serializers.SerializerMethodField()
    target_type = serializers.SerializerMethodField()
    actor = GenericRelatedField({
        get_user_model(): SimpleUserSerializer(),
        Integration: SimpleIntegrationSerializer()
    })
    target = GenericRelatedField({
        get_user_model():
        SimpleUserSerializer(),
        Comment:
        CommentSerializer(),
        Connection:
        ConnectionSerializer(),
        Task:
        SimpleTaskSerializer(),
        Application:
        ApplicationSerializer(),
        Participation:
        ParticipationSerializer(),
        TaskRequest:
        TaskRequestSerializer(),
        ProgressEvent:
        SimpleProgressEventSerializer(),
        ProgressReport:
        SimpleProgressReportSerializer(),
        Integration:
        SimpleIntegrationSerializer(),
        IntegrationActivity:
        SimpleIntegrationActivitySerializer()
    })

    class Meta(SimpleActivitySerializer.Meta):
        pass

    def get_actor_type(self, obj):
        return get_instance_type(obj.actor)

    def get_target_type(self, obj):
        return get_instance_type(obj.target)