X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/5aa13410812d3fc4b35c039bdc3f0a2edc5185a1..0c502550a4f04aa016df8729af2ae2f85c0b495a:/src/catalogue/api/fields.py?ds=sidebyside diff --git a/src/catalogue/api/fields.py b/src/catalogue/api/fields.py index 145780e2b..d95c3a857 100644 --- 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 sorl.thumbnail import default +from api.fields import AbsoluteURLField from catalogue.models import Book +from club.models import Membership class BookLiked(serializers.ReadOnlyField): @@ -10,21 +14,21 @@ class BookLiked(serializers.ReadOnlyField): def to_representation(self, value): request = self.context['request'] if not hasattr(request, 'liked_books'): - if request.user.is_authenticated(): - request.liked_books = set(Book.tagged.with_any(request.user.tag_set.all()).values_list('id', flat=True)) + if request.user.is_authenticated: + request.liked_books = set( + Book.tagged.with_any(request.user.tag_set.all()).values_list('id', flat=True) + ) else: request.liked_books = None if request.liked_books is not None: 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): - if value: - return super(ThumbnailField, self).to_representation( - default.backend.get_thumbnail(value, self.geometry) - ) + request = self.context['request'] + # FIXME: See #3955. + if True or Membership.is_active_for(request.user): + return super().to_representation(value) + else: + return None