fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
36fe056
)
cover colors in api
author
Jan Szejko
<janek37@gmail.com>
Thu, 19 Jul 2018 13:47:35 +0000
(15:47 +0200)
committer
Jan Szejko
<janek37@gmail.com>
Thu, 19 Jul 2018 13:47:35 +0000
(15:47 +0200)
src/api/handlers.py
patch
|
blob
|
history
diff --git
a/src/api/handlers.py
b/src/api/handlers.py
index
606aaa2
..
b3edaef
100644
(file)
--- a/
src/api/handlers.py
+++ b/
src/api/handlers.py
@@
-19,6
+19,7
@@
from catalogue.forms import BookImportForm
from catalogue.models import Book, Tag, BookMedia, Fragment, Collection
from catalogue.models.tag import prefetch_relations
from catalogue.utils import is_subscribed
from catalogue.models import Book, Tag, BookMedia, Fragment, Collection
from catalogue.models.tag import prefetch_relations
from catalogue.utils import is_subscribed
+from librarian.cover import WLCover
from picture.models import Picture
from picture.forms import PictureImportForm
from social.utils import likes
from picture.models import Picture
from picture.forms import PictureImportForm
from social.utils import likes
@@
-158,6
+159,10
@@
class BookDetails(object):
def simple_cover(cls, book):
return MEDIA_BASE + book.simple_cover.url if book.simple_cover else ''
def simple_cover(cls, book):
return MEDIA_BASE + book.simple_cover.url if book.simple_cover else ''
+ @classmethod
+ def cover_color(cls, book):
+ return WLCover.epoch_colors.get(book.extra_info['epoch'], '#000000')
+
class BookDetailHandler(BaseHandler, BookDetails):
""" Main handler for Book objects.
class BookDetailHandler(BaseHandler, BookDetails):
""" Main handler for Book objects.
@@
-167,7
+172,7
@@
class BookDetailHandler(BaseHandler, BookDetails):
allowed_methods = ['GET']
fields = ['title', 'parent', 'children'] + Book.formats + [
'media', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'simple_cover', 'fragment_data', 'audio_length',
allowed_methods = ['GET']
fields = ['title', 'parent', 'children'] + Book.formats + [
'media', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'simple_cover', 'fragment_data', 'audio_length',
- 'preview'] + [
+ 'preview'
, 'cover_color'
] + [
category_plural[c] for c in book_tag_categories]
@piwik_track
category_plural[c] for c in book_tag_categories]
@piwik_track
@@
-186,7
+191,8
@@
class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails):
"""
allowed_methods = ('GET',)
model = Book
"""
allowed_methods = ('GET',)
model = Book
- fields = book_tag_categories + ['href', 'title', 'url', 'cover', 'cover_thumb', 'slug', 'simple_thumb', 'has_audio']
+ fields = book_tag_categories + [
+ 'href', 'title', 'url', 'cover', 'cover_thumb', 'slug', 'simple_thumb', 'has_audio', 'cover_color']
@classmethod
def genres(cls, book):
@classmethod
def genres(cls, book):
@@
-268,7
+274,7
@@
class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails):
class BooksHandler(BookDetailHandler):
allowed_methods = ('GET', 'POST')
model = Book
class BooksHandler(BookDetailHandler):
allowed_methods = ('GET', 'POST')
model = Book
- fields = book_tag_categories + ['href', 'title', 'url', 'cover', 'cover_thumb', 'slug']
+ fields = book_tag_categories + ['href', 'title', 'url', 'cover', 'cover_thumb', '
cover_color', '
slug']
anonymous = AnonymousBooksHandler
def create(self, request, *args, **kwargs):
anonymous = AnonymousBooksHandler
def create(self, request, *args, **kwargs):
@@
-325,7
+331,7
@@
class QuerySetProxy(models.QuerySet):
class FilterBooksHandler(AnonymousBooksHandler):
fields = book_tag_categories + [
class FilterBooksHandler(AnonymousBooksHandler):
fields = book_tag_categories + [
- 'href', 'title', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'has_audio', 'slug', 'key']
+ 'href', 'title', 'url', 'cover', 'cover_thumb', '
cover_color', '
simple_thumb', 'has_audio', 'slug', 'key']
def parse_bool(self, s):
if s in ('true', 'false'):
def parse_bool(self, s):
if s in ('true', 'false'):