fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
540e76d
)
Preserve the weirdness of the API.
author
Radek Czajka
<rczajka@rczajka.pl>
Tue, 5 Feb 2019 08:52:45 +0000
(09:52 +0100)
committer
Radek Czajka
<rczajka@rczajka.pl>
Tue, 5 Feb 2019 08:52:45 +0000
(09:52 +0100)
src/api/tests/res/responses/books.json
patch
|
blob
|
history
src/api/tests/res/responses/books.xml
patch
|
blob
|
history
src/catalogue/api/serializers.py
patch
|
blob
|
history
src/catalogue/api/views.py
patch
|
blob
|
history
diff --git
a/src/api/tests/res/responses/books.json
b/src/api/tests/res/responses/books.json
index
cfd5ee3
..
4b8d11e
100644
(file)
--- a/
src/api/tests/res/responses/books.json
+++ b/
src/api/tests/res/responses/books.json
@@
-8,6
+8,7
@@
"has_audio": false,
"title": "Child",
"cover": "",
"has_audio": false,
"title": "Child",
"cover": "",
+ "liked": null,
"epoch": "",
"href": "http://testserver/api/books/child/",
"genre": "Wiersz",
"epoch": "",
"href": "http://testserver/api/books/child/",
"genre": "Wiersz",
@@
-24,6
+25,7
@@
"has_audio": false,
"title": "Grandchild",
"cover": "",
"has_audio": false,
"title": "Grandchild",
"cover": "",
+ "liked": null,
"epoch": "",
"href": "http://testserver/api/books/grandchild/",
"genre": "Sonet",
"epoch": "",
"href": "http://testserver/api/books/grandchild/",
"genre": "Sonet",
@@
-40,6
+42,7
@@
"has_audio": true,
"title": "Parent",
"cover": "cover/parent.jpg",
"has_audio": true,
"title": "Parent",
"cover": "cover/parent.jpg",
+ "liked": null,
"epoch": "Barok",
"href": "http://testserver/api/books/parent/",
"genre": "Sonet",
"epoch": "Barok",
"href": "http://testserver/api/books/parent/",
"genre": "Sonet",
diff --git
a/src/api/tests/res/responses/books.xml
b/src/api/tests/res/responses/books.xml
index
967f8e2
..
f398644
100644
(file)
--- a/
src/api/tests/res/responses/books.xml
+++ b/
src/api/tests/res/responses/books.xml
@@
-1,3
+1,2
@@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
-<response><resource><kind></kind><full_sort_key>$child$2</full_sort_key><title>Child</title><url>https://example.com/katalog/lektura/child/</url><has_audio>False</has_audio><author></author><cover></cover><slug>child</slug><epoch></epoch><href>https://example.com/api/books/child/</href><genre>Wiersz</genre><simple_thumb></simple_thumb><cover_color>#000000</cover_color><cover_thumb></cover_thumb></resource><resource><kind></kind><full_sort_key>$grandchild$3</full_sort_key><title>Grandchild</title><url>https://example.com/katalog/lektura/grandchild/</url><has_audio>False</has_audio><author></author><cover></cover><slug>grandchild</slug><epoch></epoch><href>https://example.com/api/books/grandchild/</href><genre>Sonet</genre><simple_thumb></simple_thumb><cover_color>#000000</cover_color><cover_thumb></cover_thumb></resource><resource><kind>Liryka</kind><full_sort_key>john doe$parent$1</full_sort_key><title>Parent</title><url>https://example.com/katalog/lektura/parent/</url><has_audio>True</has_audio><author>John Doe</author><cover>cover/parent.jpg</cover><slug>parent</slug><epoch>Barok</epoch><href>https://example.com/api/books/parent/</href><genre>Sonet</genre><simple_thumb>https://example.com/media/cover_api_thumb/parent.jpg</simple_thumb><cover_color>#a6820a</cover_color><cover_thumb>https://example.com/media/cover/parent.jpg-139x193</cover_thumb></resource></response>
-
+<response><resource><kind></kind><full_sort_key>$child$2</full_sort_key><title>Child</title><url>http://testserver/katalog/lektura/child/</url><cover_color>#000000</cover_color><author></author><cover></cover><epoch></epoch><href>http://testserver/api/books/child/</href><has_audio>False</has_audio><genre>Wiersz</genre><simple_thumb></simple_thumb><slug>child</slug><cover_thumb></cover_thumb><liked></liked></resource><resource><kind></kind><full_sort_key>$grandchild$3</full_sort_key><title>Grandchild</title><url>http://testserver/katalog/lektura/grandchild/</url><cover_color>#000000</cover_color><author></author><cover></cover><epoch></epoch><href>http://testserver/api/books/grandchild/</href><has_audio>False</has_audio><genre>Sonet</genre><simple_thumb></simple_thumb><slug>grandchild</slug><cover_thumb></cover_thumb><liked></liked></resource><resource><kind>Liryka</kind><full_sort_key>john doe$parent$1</full_sort_key><title>Parent</title><url>http://testserver/katalog/lektura/parent/</url><cover_color>#a6820a</cover_color><author>John Doe</author><cover>cover/parent.jpg</cover><epoch>Barok</epoch><href>http://testserver/api/books/parent/</href><has_audio>True</has_audio><genre>Sonet</genre><simple_thumb>http://testserver/media/cover_api_thumb/parent.jpg</simple_thumb><slug>parent</slug><cover_thumb>cover_thumb/parent.jpg</cover_thumb><liked></liked></resource></response>
diff --git
a/src/catalogue/api/serializers.py
b/src/catalogue/api/serializers.py
index
e8f04ca
..
ea48cdb
100644
(file)
--- a/
src/catalogue/api/serializers.py
+++ b/
src/catalogue/api/serializers.py
@@
-24,16
+24,17
@@
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.
Char
Field()
+ cover = serializers.
File
Field()
cover_thumb = ThumbnailField('139x193', source='cover')
class Meta:
cover_thumb = ThumbnailField('139x193', source='cover')
class Meta:
@@
-41,20
+42,17
@@
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 Book
Serializer(Base
BookSerializer):
-
liked = BookLike
d()
- cover
= serializers.File
Field()
+class Book
ListSerializer(
BookSerializer):
+
cover = serializers.CharFiel
d()
+ cover
_thumb = serializers.Char
Field()
- class Meta:
- model = Book
- fields = BaseBookSerializer.Meta.fields + ['liked']
- legacy_non_null_fields = BaseBookSerializer.Meta.legacy_non_null_fields
+ Meta = BookSerializer.Meta
class MediaSerializer(LegacyMixin, serializers.ModelSerializer):
class MediaSerializer(LegacyMixin, serializers.ModelSerializer):
diff --git
a/src/catalogue/api/views.py
b/src/catalogue/api/views.py
index
e21aab7
..
f3b7193
100644
(file)
--- a/
src/catalogue/api/views.py
+++ b/
src/catalogue/api/views.py
@@
-24,12
+24,12
@@
class CollectionDetail(RetrieveAPIView):
class BookList(ListAPIView):
permission_classes = [DjangoModelPermissionsOrAnonReadOnly]
queryset = Book.objects.none() # Required for DjangoModelPermissions
class BookList(ListAPIView):
permission_classes = [DjangoModelPermissionsOrAnonReadOnly]
queryset = Book.objects.none() # Required for DjangoModelPermissions
- serializer_class = serializers.B
aseBook
Serializer
+ serializer_class = serializers.B
ookList
Serializer
def get_queryset(self):
try:
tags, ancestors = read_tags(
def get_queryset(self):
try:
tags, ancestors = read_tags(
- self.kwargs
['tags']
, self.request,
+ self.kwargs
.get('tags', '')
, self.request,
allowed=('author', 'epoch', 'kind', 'genre')
)
except ValueError:
allowed=('author', 'epoch', 'kind', 'genre')
)
except ValueError: