fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More Py3 compatibility fixes.
[wolnelektury.git]
/
src
/
catalogue
/
api
/
serializers.py
diff --git
a/src/catalogue/api/serializers.py
b/src/catalogue/api/serializers.py
index
e8f04ca
..
a5069e3
100644
(file)
--- a/
src/catalogue/api/serializers.py
+++ b/
src/catalogue/api/serializers.py
@@
-1,7
+1,11
@@
+# -*- 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 rest_framework import serializers
-from api.fields import AbsoluteURLField, LegacyMixin
+from api.fields import AbsoluteURLField, LegacyMixin
, ThumbnailField
from catalogue.models import Book, Collection, Tag, BookMedia, Fragment
from catalogue.models import Book, Collection, Tag, BookMedia, Fragment
-from .fields import BookLiked
, ThumbnailField
+from .fields import BookLiked
class TagSerializer(serializers.ModelSerializer):
class TagSerializer(serializers.ModelSerializer):
@@
-24,16
+28,16
@@
class TagDetailSerializer(serializers.ModelSerializer):
fields = ['name', 'url', 'sort_key', 'description']
fields = ['name', 'url', 'sort_key', 'description']
-class B
aseB
ookSerializer(LegacyMixin, serializers.ModelSerializer):
+class BookSerializer(LegacyMixin, serializers.ModelSerializer):
author = serializers.CharField(source='author_unicode')
kind = serializers.CharField(source='kind_unicode')
epoch = serializers.CharField(source='epoch_unicode')
genre = serializers.CharField(source='genre_unicode')
author = serializers.CharField(source='author_unicode')
kind = serializers.CharField(source='kind_unicode')
epoch = serializers.CharField(source='epoch_unicode')
genre = serializers.CharField(source='genre_unicode')
+ liked = BookLiked()
simple_thumb = serializers.FileField(source='cover_api_thumb')
href = AbsoluteURLField(view_name='catalogue_api_book', view_args=['slug'])
url = AbsoluteURLField()
simple_thumb = serializers.FileField(source='cover_api_thumb')
href = AbsoluteURLField(view_name='catalogue_api_book', view_args=['slug'])
url = AbsoluteURLField()
- cover = serializers.CharField()
cover_thumb = ThumbnailField('139x193', source='cover')
class Meta:
cover_thumb = ThumbnailField('139x193', source='cover')
class Meta:
@@
-41,20
+45,26
@@
class BaseBookSerializer(LegacyMixin, serializers.ModelSerializer):
fields = [
'kind', 'full_sort_key', 'title', 'url', 'cover_color', 'author',
'cover', 'epoch', 'href', 'has_audio', 'genre',
fields = [
'kind', 'full_sort_key', 'title', 'url', 'cover_color', 'author',
'cover', 'epoch', 'href', 'has_audio', 'genre',
- 'simple_thumb', 'slug', 'cover_thumb']
+ 'simple_thumb', 'slug', 'cover_thumb'
, 'liked'
]
legacy_non_null_fields = [
'kind', 'author', 'epoch', 'genre',
'cover', 'simple_thumb', 'cover_thumb']
legacy_non_null_fields = [
'kind', 'author', 'epoch', 'genre',
'cover', 'simple_thumb', 'cover_thumb']
-class BookSerializer(BaseBookSerializer):
- liked = BookLiked()
- cover = serializers.FileField()
+class BookListSerializer(BookSerializer):
+ cover = serializers.CharField()
+ cover_thumb = serializers.CharField()
+
+ Meta = BookSerializer.Meta
+
+
+class FilterBookListSerializer(BookListSerializer):
+ key = serializers.CharField()
class Meta:
model = Book
class Meta:
model = Book
- fields = B
aseBookSerializer.Meta.fields + ['liked
']
- legacy_non_null_fields = B
aseBook
Serializer.Meta.legacy_non_null_fields
+ fields = B
ookListSerializer.Meta.fields + ['key
']
+ legacy_non_null_fields = B
ookList
Serializer.Meta.legacy_non_null_fields
class MediaSerializer(LegacyMixin, serializers.ModelSerializer):
class MediaSerializer(LegacyMixin, serializers.ModelSerializer):
@@
-109,7
+119,13
@@
class BookPreviewSerializer(BookDetailSerializer):
legacy_non_null_fields = BookDetailSerializer.Meta.legacy_non_null_fields
legacy_non_null_fields = BookDetailSerializer.Meta.legacy_non_null_fields
-class EbookSerializer(BookSerializer):
+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')
+
class Meta:
model = Book
fields = ['author', 'href', 'title', 'cover', 'slug'] + Book.ebook_formats
class Meta:
model = Book
fields = ['author', 'href', 'title', 'cover', 'slug'] + Book.ebook_formats