-# -*- coding: utf-8 -*-
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from rest_framework import serializers
from api.fields import AbsoluteURLField, LegacyMixin, ThumbnailField
from catalogue.models import Book, Collection, Tag, BookMedia, Fragment
-from .fields import BookLiked
+from .fields import BookLiked, EmbargoURLField
class TagSerializer(serializers.ModelSerializer):
fields = ['name', 'url', 'sort_key', 'description']
+class TranslatorSerializer(serializers.Serializer):
+ name = serializers.CharField(source='*')
+
+
class BookSerializer(LegacyMixin, serializers.ModelSerializer):
author = serializers.CharField(source='author_unicode')
kind = serializers.CharField(source='kind_unicode')
class MediaSerializer(LegacyMixin, serializers.ModelSerializer):
- url = serializers.FileField(source='file')
+ url = EmbargoURLField(source='file_url')
class Meta:
model = BookMedia
url = AbsoluteURLField()
authors = TagSerializer(many=True)
+ translators = TranslatorSerializer(many=True)
epochs = TagSerializer(many=True)
genres = TagSerializer(many=True)
kinds = TagSerializer(many=True)
parent = BookSerializer()
children = BookSerializer(many=True)
- xml = AbsoluteURLField(source='xml_url')
- html = AbsoluteURLField(source='html_url')
- txt = AbsoluteURLField(source='txt_url')
- fb2 = AbsoluteURLField(source='fb2_url')
- epub = AbsoluteURLField(source='epub_url')
- mobi = AbsoluteURLField(source='mobi_url')
- pdf = AbsoluteURLField(source='pdf_url')
+ xml = EmbargoURLField(source='xml_url')
+ html = EmbargoURLField(source='html_url')
+ txt = EmbargoURLField(source='txt_url')
+ fb2 = EmbargoURLField(source='fb2_url')
+ epub = EmbargoURLField(source='epub_url')
+ mobi = EmbargoURLField(source='mobi_url')
+ pdf = EmbargoURLField(source='pdf_url')
media = MediaSerializer(many=True)
cover_thumb = ThumbnailField('139x193', source='cover')
simple_thumb = serializers.FileField(source='cover_api_thumb')
class Meta:
model = Book
fields = [
- 'title', 'url',
- 'epochs', 'genres', 'kinds', 'authors',
+ 'title', 'url', 'language',
+ 'epochs', 'genres', 'kinds', 'authors', 'translators',
'fragment_data', 'children', 'parent', 'preview',
'epub', 'mobi', 'pdf', 'html', 'txt', 'fb2', 'xml', 'media', 'audio_length',
- 'cover_color', 'simple_cover', 'cover_thumb', 'cover', 'simple_thumb'
+ 'cover_color', 'simple_cover', 'cover_thumb', 'cover', 'simple_thumb',
+ 'isbn_pdf', 'isbn_epub', 'isbn_mobi',
]
legacy_non_null_fields = ['html', 'txt', 'fb2', 'epub', 'mobi', 'pdf',
'cover', 'simple_cover', 'cover_thumb', 'simple_thumb']
class EbookSerializer(BookListSerializer):
- txt = AbsoluteURLField(source='txt_url')
- fb2 = AbsoluteURLField(source='fb2_url')
- epub = AbsoluteURLField(source='epub_url')
- mobi = AbsoluteURLField(source='mobi_url')
- pdf = AbsoluteURLField(source='pdf_url')
+ txt = EmbargoURLField(source='txt_url')
+ fb2 = EmbargoURLField(source='fb2_url')
+ epub = EmbargoURLField(source='epub_url')
+ mobi = EmbargoURLField(source='mobi_url')
+ pdf = EmbargoURLField(source='pdf_url')
class Meta:
model = Book
class CollectionSerializer(serializers.ModelSerializer):
- books = BookSerializer(many=True, source='get_books')
+ books = BookSerializer(many=True, source='get_books', read_only=True)
+ book_slugs = serializers.CharField(write_only=True)
url = AbsoluteURLField()
class Meta:
model = Collection
- fields = ['url', 'books', 'description', 'title']
+ fields = ['url', 'books', 'description', 'title', 'book_slugs']
class FragmentSerializer(serializers.ModelSerializer):