fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Machina preview.
[wolnelektury.git]
/
src
/
catalogue
/
api
/
fields.py
diff --git
a/src/catalogue/api/fields.py
b/src/catalogue/api/fields.py
index
145780e
..
48c0095
100644
(file)
--- a/
src/catalogue/api/fields.py
+++ b/
src/catalogue/api/fields.py
@@
-1,6
+1,10
@@
+# 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
sorl.thumbnail import default
+from
api.fields import AbsoluteURLField
from catalogue.models import Book
from catalogue.models import Book
+from club.models import Membership
class BookLiked(serializers.ReadOnlyField):
class BookLiked(serializers.ReadOnlyField):
@@
-18,13
+22,10
@@
class BookLiked(serializers.ReadOnlyField):
return value in request.liked_books
return value in request.liked_books
-class ThumbnailField(serializers.FileField):
- def __init__(self, geometry, *args, **kwargs):
- self.geometry = geometry
- super(ThumbnailField, self).__init__(*args, **kwargs)
-
+class EmbargoURLField(AbsoluteURLField):
def to_representation(self, value):
def to_representation(self, value):
- if value:
- return super(ThumbnailField, self).to_representation(
- default.backend.get_thumbnail(value, self.geometry)
- )
+ request = self.context['request']
+ if Membership.is_active_for(request.user):
+ return super().to_representation(value)
+ else:
+ return None