# pylint: disable=abstract-method
from django.contrib.auth import get_user_model
from rest_framework import serializers
from .models import Address
[docs]class GradeSerializer(serializers.Serializer):
number = serializers.IntegerField()
name = serializers.CharField(max_length=20)
[docs]class AddressSerializer(serializers.ModelSerializer):
street = serializers.CharField(max_length=500)
city = serializers.CharField(max_length=200)
state = serializers.CharField(max_length=100)
postal_code = serializers.CharField(max_length=10)
[docs]class StudentSerializer(serializers.HyperlinkedModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name="api_user_profile_detail")
first_name = serializers.CharField(max_length=200)
last_name = serializers.CharField(max_length=200)
user_type = serializers.CharField(max_length=100)
username = serializers.CharField(max_length=100)
grade = GradeSerializer()
[docs]class CounselorTeacherSerializer(serializers.HyperlinkedModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name="api_user_profile_detail")
first_name = serializers.CharField(max_length=200)
last_name = serializers.CharField(max_length=200)
user_type = serializers.CharField(max_length=100)
username = serializers.CharField(max_length=100)
[docs]class HyperlinkedImageField(serializers.HyperlinkedIdentityField):
[docs] def get_url(self, obj, view_name, request, format): # pylint: disable=redefined-builtin
s = super().get_url(obj, view_name, request, format)
if "format=" in s:
return "{}format=jpg".format(s.split("format=", 1)[0])
return s
[docs]class UserSerializer(serializers.ModelSerializer):
grade = GradeSerializer()
address = AddressSerializer()
counselor = CounselorTeacherSerializer()
ion_username = serializers.CharField(max_length=500)
display_name = serializers.CharField(max_length=400)
nickname = serializers.CharField(max_length=200)
title = serializers.CharField(max_length=200)
first_name = serializers.CharField(max_length=200)
middle_name = serializers.CharField(max_length=200)
last_name = serializers.CharField(max_length=200)
sex = serializers.CharField(max_length=10)
user_type = serializers.CharField(max_length=100)
graduation_year = serializers.IntegerField()
tj_email = serializers.StringRelatedField()
student_id = serializers.IntegerField()
emails = serializers.StringRelatedField(many=True)
phones = serializers.StringRelatedField(many=True)
websites = serializers.StringRelatedField(many=True)
picture = HyperlinkedImageField(view_name="api_user_profile_picture_default", format="jpg")
absences = serializers.IntegerField(source="absence_count")