X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/24f677a3979ba3f1bdfe420c03ad5e3f8b0398c2..65c9feda79d2b2c94cb7dcd561318a83fd796f0a:/src/api/fields.py diff --git a/src/api/fields.py b/src/api/fields.py index 1ce83cc3e..278af6aea 100644 --- a/src/api/fields.py +++ b/src/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 django.core.urlresolvers import reverse -from paypal.rest import user_is_subscribed +from club.models import Membership class AbsoluteURLField(serializers.ReadOnlyField): @@ -40,4 +44,16 @@ class UserPremiumField(serializers.ReadOnlyField): super(UserPremiumField, self).__init__(*args, source='*', **kwargs) def to_representation(self, value): - return user_is_subscribed(value) + return Membership.is_active_for(value) + + +class ThumbnailField(serializers.FileField): + def __init__(self, geometry, *args, **kwargs): + self.geometry = geometry + super(ThumbnailField, self).__init__(*args, **kwargs) + + def to_representation(self, value): + if value: + return super(ThumbnailField, self).to_representation( + default.backend.get_thumbnail(value, self.geometry) + )