1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.contrib.auth.models import User
5 from rest_framework import serializers
6 from .fields import UserPremiumField
7 from .models import BookUserData
10 class PlainSerializer(serializers.ModelSerializer):
11 def to_representation(self, value):
12 value = super(PlainSerializer, self).to_representation(value)
13 return value.values()[0]
16 class UserSerializer(serializers.ModelSerializer):
17 premium = UserPremiumField()
18 confirmed = serializers.BooleanField(source='is_active')
22 fields = ['username', 'premium', 'confirmed']
25 class BookUserDataSerializer(serializers.ModelSerializer):
31 class LoginSerializer(serializers.Serializer):
32 username = serializers.CharField()
33 password = serializers.CharField(style={'input_type': 'password'})
37 class RegisterSerializer(serializers.Serializer):
38 email = serializers.CharField()
39 password = serializers.CharField(style={'input_type': 'password'})
40 options = serializers.ListField(child=serializers.IntegerField())
43 class RefreshTokenSerializer(serializers.Serializer):
44 refresh_token = serializers.CharField(style={'input_type': 'password'})