1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.contrib.auth.models import User
6 from rest_framework import serializers
7 from .fields import UserPremiumField, AbsoluteURLField, ThumbnailField
8 from .models import BookUserData
9 from migdal.models import Entry, Photo
12 class PlainSerializer(serializers.ModelSerializer):
13 def to_representation(self, value):
14 value = super(PlainSerializer, self).to_representation(value)
15 return value.values()[0]
18 class UserSerializer(serializers.ModelSerializer):
19 premium = UserPremiumField()
23 fields = ['username', 'premium']
26 class BookUserDataSerializer(serializers.ModelSerializer):
32 class BlogGalleryUrlSerializer(PlainSerializer):
38 class BlogSerializer(serializers.ModelSerializer):
39 url = AbsoluteURLField()
40 image_url = serializers.FileField(source='image')
41 image_thumb = ThumbnailField('193x193', source='image')
42 key = serializers.DateTimeField(source='first_published_at')
43 gallery_urls = BlogGalleryUrlSerializer(many=True, source='photo_set')
44 body = serializers.CharField()
45 lead = serializers.CharField()
49 fields = ['title', 'lead', 'body', 'place', 'time', 'image_url', 'image_thumb',
50 'gallery_urls', 'type', 'key', 'url']