Esempio n. 1
0
class ReactionSerializer(serializers.ModelSerializer):
    """
    Serializer for Wallpost Reactions.
    """
    author = UserPreviewSerializer()
    text = ContentTextField()
    wallpost = serializers.PrimaryKeyRelatedField(queryset=Wallpost.objects)

    class Meta:
        model = Reaction
        fields = ('created', 'author', 'text', 'id', 'wallpost')
Esempio n. 2
0
class TextWallpostSerializer(WallpostSerializerBase):
    """
    Serializer for TextWallposts. This should not be used directly but instead
    should be subclassed for the specific
    model it's a Wallpost about. See ProjectTextWallpost for an example.
    """
    text = ContentTextField()

    class Meta:
        model = TextWallpost
        fields = WallpostSerializerBase.Meta.fields + ('text',)
Esempio n. 3
0
class SystemWallpostSerializer(WallpostSerializerBase):
    """
    Serializer for TextWallposts. This should not be used directly but instead
    should be subclassed for the specific
    model it's a Wallpost about. See ProjectTextWallpost for an example.
    """
    text = ContentTextField()

    # related_type = serializers.CharField(source='related_type.model')
    # related_object = WallpostRelatedField(source='related_object')

    class Meta:
        model = TextWallpost
        fields = WallpostSerializerBase.Meta.fields + ('text',)
Esempio n. 4
0
class MediaWallpostSerializer(WallpostSerializerBase):
    """
    Serializer for MediaWallposts. This should not be used directly but instead
    should be subclassed for the specific
    model it's a Wallpost about. See ProjectMediaWallpost for an example.
    """
    text = ContentTextField(required=False)
    video_html = OEmbedField(source='video_url',
                             maxwidth='560',
                             maxheight='315')
    photos = MediaWallpostPhotoSerializer(many=True, required=False)
    video_url = serializers.CharField(required=False, allow_blank=True)

    class Meta:
        model = MediaWallpost
        fields = WallpostSerializerBase.Meta.fields + ('text', 'video_html',
                                                       'video_url', 'photos')
Esempio n. 5
0
class TextWallpostSerializer(WallpostSerializerBase):
    """
    Serializer for TextWallposts. This should not be used directly but instead
    should be subclassed for the specific
    model it's a Wallpost about. See ProjectTextWallpost for an example.
    """
    text = ContentTextField()

    class Meta(object):
        model = TextWallpost
        fields = WallpostSerializerBase.Meta.fields + ('text', )

    def validate(self, data):
        if ('donation' in data
                and TextWallpost.objects.filter(donation=data['donation'])):
            raise ValidationError("Wallpost for donation already exists.")

        return super(WallpostSerializerBase, self).validate(data)