class BaseUserPreviewSerializer(PrivateProfileMixin, serializers.ModelSerializer):
    """
    Serializer for a subset of a member's public profile. This is usually
    embedded into other serializers.
    """

    def __init__(self, *args, **kwargs):
        kwargs['read_only'] = True
        super(BaseUserPreviewSerializer, self).__init__(*args, **kwargs)

    avatar = SorlImageField('133x133', source='picture', crop='center')

    # TODO: Remove first/last name and only use these
    full_name = serializers.ReadOnlyField(
        source='get_full_name', read_only=True)
    short_name = serializers.ReadOnlyField(
        source='get_short_name', read_only=True)
    is_active = serializers.BooleanField(read_only=True)
    is_anonymous = serializers.SerializerMethodField()

    def get_is_anonymous(self, obj):
        return False

    class Meta(object):
        model = BB_USER_MODEL
        fields = ('id', 'first_name', 'last_name', 'initials', 'about_me',
                  'avatar', 'full_name', 'short_name', 'is_active', 'is_anonymous')
Example #2
0
class SlideSerializer(serializers.ModelSerializer):
    image = SorlImageField('1600x674', crop='center')
    background_image = SorlImageField('1600x674', crop='center')

    class Meta:
        model = Slide
        fields = (
            'background_image',
            'body',
            'id',
            'image',
            'link_text',
            'link_url',
            'tab_text',
            'title',
            'video_url',
        )
Example #3
0
class ProjectTinyPreviewSerializer(serializers.ModelSerializer):
    id = serializers.CharField(read_only=True)
    image = SorlImageField('400x300', crop='center')
    latitude = serializers.FloatField(source='projectlocation.latitude')
    longitude = serializers.FloatField(source='projectlocation.longitude')

    class Meta:
        model = Project
        fields = ('id', 'title', 'slug', 'status', 'image', 'latitude', 'longitude')
Example #4
0
class SlideSerializer(serializers.ModelSerializer):
    author = serializers.PrimaryKeyRelatedField(queryset=Member.objects)
    image = SorlImageField('800x600', crop='center')
    background_image = serializers.CharField(
        source='background_image_full_path')
    video = OEmbedField('video_url')

    class Meta:
        model = Slide
        fields = '__all__'
Example #5
0
class NewsItemSerializer(serializers.ModelSerializer):
    id = serializers.CharField(source='slug')
    body = NewsItemContentsField(source='contents')
    main_image = SorlImageField('800x400')
    author = UserPreviewSerializer()

    class Meta:
        model = NewsItem
        fields = ('id', 'title', 'body', 'main_image', 'author',
                  'publication_date', 'allow_comments', 'language',
                  'main_image')
Example #6
0
class NewsItemSerializer(serializers.ModelSerializer):
    id = serializers.CharField(source='slug')
    blocks = BlockSerializer(source='contents.contentitems.all', many=True)
    main_image = SorlImageField('800x400')
    author = UserPreviewSerializer()

    class Meta(object):
        model = NewsItem
        fields = ('id', 'title', 'blocks', 'main_image', 'author',
                  'publication_date', 'allow_comments', 'language',
                  'main_image')
Example #7
0
class LinkSerializer(serializers.ModelSerializer):
    image = SorlImageField('800x600', crop='center')

    class Meta(object):
        model = ContentLink
        fields = (
            'id',
            'image',
            'action_link',
            'action_text',
        )
Example #8
0
class StepSerializer(serializers.ModelSerializer):
    image = SorlImageField('200x200', crop='center')
    text = SafeField(required=False, allow_blank=True)

    class Meta(object):
        model = Step
        fields = (
            'id',
            'image',
            'header',
            'text',
        )
Example #9
0
class ProjectMediaSerializer(serializers.ModelSerializer):
    id = serializers.CharField(source='slug')
    image = SorlImageField('1200x600', crop='center',
                           watermark='images/completed.png',
                           watermark_pos='-40 40',
                           watermark_size='213x255')
    pictures = ProjectWallpostPhotoSerializer(source='wallpost_photos', many=True)
    videos = ProjectWallpostVideoSerializer(source='wallpost_videos', many=True)

    class Meta:
        model = Project
        fields = ('id', 'title', 'pictures', 'videos', 'image')
class MemberPlatformSettingsSerializer(serializers.ModelSerializer):
    background = SorlImageField('1408x1080', crop='center')

    class Meta(object):
        model = MemberPlatformSettings
        fields = (
            'require_consent',
            'consent_link',
            'closed',
            'email_domain',
            'confirm_signup',
            'login_methods',
            'background',
        )
Example #11
0
class ResultPageSerializer(serializers.ModelSerializer):
    blocks = BlockSerializer(source='content.contentitems.all.translated',
                             many=True)
    image = ImageSerializer()
    share_image = SorlImageField(
        '1200x600',
        source='image',
        crop='center',
    )

    class Meta(object):
        model = ResultPage
        fields = ('id', 'title', 'slug', 'start_date', 'image', 'share_image',
                  'end_date', 'description', 'blocks')
Example #12
0
class UserProfileSerializer(PrivateProfileMixin, serializers.ModelSerializer):
    """
    Serializer for a member's public profile.
    """
    url = serializers.HyperlinkedIdentityField(view_name='user-profile-detail',
                                               lookup_field='pk')
    picture = ImageSerializer(required=False)
    date_joined = serializers.DateTimeField(read_only=True)

    full_name = serializers.CharField(source='get_full_name', read_only=True)
    short_name = serializers.CharField(source='get_short_name', read_only=True)

    primary_language = serializers.CharField(required=False,
                                             default=properties.LANGUAGE_CODE)
    location = serializers.PrimaryKeyRelatedField(required=False, allow_null=True,
                                                  queryset=Location.objects)
    avatar = SorlImageField('133x133', source='picture', crop='center',
                            required=False)

    skill_ids = serializers.PrimaryKeyRelatedField(many=True,
                                                   source='skills',
                                                   required=False,
                                                   queryset=Skill.objects)
    favourite_theme_ids = serializers.PrimaryKeyRelatedField(
        many=True, source='favourite_themes', queryset=ProjectTheme.objects)

    project_count = serializers.ReadOnlyField()
    donation_count = serializers.ReadOnlyField()
    fundraiser_count = serializers.ReadOnlyField()
    task_count = serializers.ReadOnlyField()
    time_spent = serializers.ReadOnlyField()
    tasks_performed = serializers.ReadOnlyField()
    partner_organization = OrganizationPreviewSerializer(allow_null=True, read_only=True, required=False)
    is_active = serializers.BooleanField(read_only=True)

    class Meta:
        model = BB_USER_MODEL
        fields = (
            'id', 'url', 'full_name', 'short_name', 'initials', 'picture',
            'primary_language', 'about_me', 'location', 'avatar',
            'project_count', 'donation_count', 'date_joined',
            'fundraiser_count', 'task_count', 'time_spent', 'is_active',
            'tasks_performed', 'website', 'twitter', 'facebook',
            'skypename', 'skill_ids', 'favourite_theme_ids', 'partner_organization',
        )
Example #13
0
class BaseMemberSerializer(ModelSerializer):
    avatar = SorlImageField('133x133', source='picture', crop='center')
    full_name = serializers.ReadOnlyField(source='get_full_name',
                                          read_only=True)
    is_active = serializers.BooleanField(read_only=True)
    short_name = serializers.ReadOnlyField(source='get_short_name',
                                           read_only=True)
    is_anonymous = serializers.SerializerMethodField()

    class Meta(object):
        model = Member
        fields = ('id', 'first_name', 'last_name', 'initials', 'avatar',
                  'full_name', 'short_name', 'is_active', 'date_joined',
                  'about_me', 'is_co_financer', 'is_anonymous')

    def get_is_anonymous(self, obj):
        return False

    class JSONAPIMeta(object):
        resource_name = 'members'
Example #14
0
class MemberSerializer(ModelSerializer):
    avatar = SorlImageField('133x133', source='picture', crop='center')
    full_name = serializers.ReadOnlyField(source='get_full_name',
                                          read_only=True)
    is_active = serializers.BooleanField(read_only=True)
    short_name = serializers.ReadOnlyField(source='get_short_name',
                                           read_only=True)

    class Meta(object):
        model = Member
        fields = ('id', 'first_name', 'last_name', 'initials', 'avatar',
                  'full_name', 'short_name', 'is_active', 'date_joined',
                  'about_me', 'is_co_financer', 'is_anonymous')

    class JSONAPIMeta(object):
        resource_name = 'members'

    def to_representation(self, instance):
        if 'parent' in self.context and getattr(self.context['parent'],
                                                'anonymized', False):
            return {"id": 0, "is_anonymous": True}
        return BaseMemberSerializer(
            instance, context=self.context).to_representation(instance)
Example #15
0
class QuoteSerializer(serializers.ModelSerializer):
    image = SorlImageField('100x100', crop='center')

    class Meta(object):
        model = Quote
        fields = ('id', 'name', 'quote', 'image')
Example #16
0
class FaviconsSerializer(serializers.Serializer):
    large = SorlImageField('194x194', source='*')
    small = SorlImageField('32x32', source='*')
Example #17
0
class LogoSerializer(serializers.ModelSerializer):
    image = SorlImageField('x150', crop='center')

    class Meta(object):
        model = Logo
        fields = ('id', 'image', 'link')