+# 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 django.core.urlresolvers import reverse
+from sorl.thumbnail import default
+from django.urls import reverse
+from club.models import Membership
class AbsoluteURLField(serializers.ReadOnlyField):
if field in value and value[field] is None:
value[field] = ''
return value
+
+
+class UserPremiumField(serializers.ReadOnlyField):
+ def __init__(self, *args, **kwargs):
+ super(UserPremiumField, self).__init__(*args, source='*', **kwargs)
+
+ def to_representation(self, 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)
+ )