# Path: students/models.py
# class Class(models.Model):
#     CLASS_NUMBERS = (
#         (8, 8),
#         (9, 9),
#         (10, 10),
#         (11, 11),
#         (12, 12),
#     )
#     CLASS_NUMBER_VALIDATORS = [MinValueValidator(8), MaxValueValidator(12)]
# 
#     CLASS_LETTERS = (
#         ('A', 'A'),
#         ('B', 'B'),
#         ('V', 'V'),
#         ('G', 'G'),
#     )
# 
#     number = models.IntegerField(validators=CLASS_NUMBER_VALIDATORS, choices=CLASS_NUMBERS)
#     letter = models.CharField(max_length=1, choices=CLASS_LETTERS)
# 
#     def __str__(self):
#         return '{}{}'.format(self.number, self.letter)
# 
#     class Meta:
#         ordering = ['number', 'letter']
#         verbose_name_plural = 'classes'
# 
# class Subject(models.Model):
#     title = models.CharField(unique=True, max_length=50)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         ordering = ['title']
# 
# class Student(Account):
#     clazz = models.ForeignKey(Class, related_name='students', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.user.username, self.clazz)
# 
# class Teacher(Account):
#     subject = models.ForeignKey(Subject, related_name='teachers', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.user.username, self.subject)
# 
# class Grade(models.Model):
#     GRADE_VALIDATORS = [MinValueValidator(2), MaxValueValidator(6)]
# 
#     value = models.FloatField(validators=GRADE_VALIDATORS)
#     subject = models.ForeignKey(Subject, related_name='grades', on_delete=models.CASCADE)
#     student = models.ForeignKey(Student, related_name='grades', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} - {} ({})'.format(self.student, self.subject, self.value)
# 
# Path: students/utils.py
# def generate_activation_key():
#     return uuid.uuid4().hex
# 
# def send_verification_email(user):
#     subject = 'ELSYSER Account activation'
#     client_url = BASE_CLIENT_URL + 'auth/activate/{activation_key}/'.format(
#         activation_key=user.student.activation_key
#     )
#     message = 'Visit this link to activate your ELSYSER account: {url}'.format(url=client_url)
# 
#     msg = 'Hello, {full_name}!\n\n{message}\n\n ~ The ELSYSER Team ~'.format(
#         full_name=user.get_full_name(),
#         message=message
#     )
# 
#     send_mail(
#         subject=subject,
#         message=msg,
#         from_email=settings.DEFAULT_FROM_EMAIL,
#         recipient_list=[user.email],
#         fail_silently=False
#     )
# 
# def send_creation_email(user, model):
#     model_type = model.__class__.__name__.lower()
#     client_resource_link = '{model_type}s/{id}/'.format(model_type=model_type, id=model.id)
# 
#     template_context = {
#         'full_name': user.get_full_name(),
#         'type': model_type,
#         'model': model,
#         'author': model.author,
#         'link': BASE_CLIENT_URL + client_resource_link
#     }
#     html_content = render_to_string('utils/email.html', context=template_context)
#     text_content = strip_tags(html_content)
# 
#     subject = 'ELSYSER {resource} added'.format(resource=model_type)
# 
#     msg = EmailMultiAlternatives(
#         subject,
#         text_content,
#         settings.DEFAULT_FROM_EMAIL,
#         [user.email]
#     )
#     msg.attach_alternative(html_content, "text/html")
#     msg.send()


import re
import requests
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib.auth.password_validation import validate_password as auth_validate_password
from django.core.validators import validate_email, ValidationError
from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from .models import Class, Subject, Student, Teacher, Grade
from .utils import generate_activation_key, send_verification_email, send_creation_email
    subject = SubjectSerializer()

    class Meta:
        model = Teacher
        fields = DefaultProfileSerializer.Meta.fields + ('subject',)


class DefaultAuthorSerializer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)


class StudentAuthorSerializer(DefaultAuthorSerializer):
    clazz = ClassSerializer(read_only=True)

    class Meta:
        model = Student
        fields = ('id', 'user', 'clazz')


class TeacherAuthorSerializer(DefaultAuthorSerializer):
    class Meta:
        model = Teacher
        fields = ('id', 'user', 'subject')


class GradesSerializer(serializers.ModelSerializer):
    subject = SubjectSerializer(read_only=True)
    student = StudentSerializer(read_only=True)

    class Meta:

# Path: students/models.py
# class Class(models.Model):
#     CLASS_NUMBERS = (
#         (8, 8),
#         (9, 9),
#         (10, 10),
#         (11, 11),
#         (12, 12),
#     )
#     CLASS_NUMBER_VALIDATORS = [MinValueValidator(8), MaxValueValidator(12)]
# 
#     CLASS_LETTERS = (
#         ('A', 'A'),
#         ('B', 'B'),
#         ('V', 'V'),
#         ('G', 'G'),
#     )
# 
#     number = models.IntegerField(validators=CLASS_NUMBER_VALIDATORS, choices=CLASS_NUMBERS)
#     letter = models.CharField(max_length=1, choices=CLASS_LETTERS)
# 
#     def __str__(self):
#         return '{}{}'.format(self.number, self.letter)
# 
#     class Meta:
#         ordering = ['number', 'letter']
#         verbose_name_plural = 'classes'
# 
# class Subject(models.Model):
#     title = models.CharField(unique=True, max_length=50)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         ordering = ['title']
# 
# class Student(Account):
#     clazz = models.ForeignKey(Class, related_name='students', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.user.username, self.clazz)
# 
# class Teacher(Account):
#     subject = models.ForeignKey(Subject, related_name='teachers', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.user.username, self.subject)
# 
# class Grade(models.Model):
#     GRADE_VALIDATORS = [MinValueValidator(2), MaxValueValidator(6)]
# 
#     value = models.FloatField(validators=GRADE_VALIDATORS)
#     subject = models.ForeignKey(Subject, related_name='grades', on_delete=models.CASCADE)
#     student = models.ForeignKey(Student, related_name='grades', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} - {} ({})'.format(self.student, self.subject, self.value)
# 
# Path: students/utils.py
# def generate_activation_key():
#     return uuid.uuid4().hex
# 
# def send_verification_email(user):
#     subject = 'ELSYSER Account activation'
#     client_url = BASE_CLIENT_URL + 'auth/activate/{activation_key}/'.format(
#         activation_key=user.student.activation_key
#     )
#     message = 'Visit this link to activate your ELSYSER account: {url}'.format(url=client_url)
# 
#     msg = 'Hello, {full_name}!\n\n{message}\n\n ~ The ELSYSER Team ~'.format(
#         full_name=user.get_full_name(),
#         message=message
#     )
# 
#     send_mail(
#         subject=subject,
#         message=msg,
#         from_email=settings.DEFAULT_FROM_EMAIL,
#         recipient_list=[user.email],
#         fail_silently=False
#     )
# 
# def send_creation_email(user, model):
#     model_type = model.__class__.__name__.lower()
#     client_resource_link = '{model_type}s/{id}/'.format(model_type=model_type, id=model.id)
# 
#     template_context = {
#         'full_name': user.get_full_name(),
#         'type': model_type,
#         'model': model,
#         'author': model.author,
#         'link': BASE_CLIENT_URL + client_resource_link
#     }
#     html_content = render_to_string('utils/email.html', context=template_context)
#     text_content = strip_tags(html_content)
# 
#     subject = 'ELSYSER {resource} added'.format(resource=model_type)
# 
#     msg = EmailMultiAlternatives(
#         subject,
#         text_content,
#         settings.DEFAULT_FROM_EMAIL,
#         [user.email]
#     )
#     msg.attach_alternative(html_content, "text/html")
#     msg.send()


# Path: students/serializers.py
import re
import requests
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib.auth.password_validation import validate_password as auth_validate_password
from django.core.validators import validate_email, ValidationError
from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from .models import Class, Subject, Student, Teacher, Grade
from .utils import generate_activation_key, send_verification_email, send_creation_email

    subject = SubjectSerializer()

    class Meta:
        model = Teacher
        fields = DefaultProfileSerializer.Meta.fields + ('subject',)


class DefaultAuthorSerializer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)


class StudentAuthorSerializer(DefaultAuthorSerializer):
    clazz = ClassSerializer(read_only=True)

    class Meta:
        model = Student
        fields = ('id', 'user', 'clazz')


class TeacherAuthorSerializer(DefaultAuthorSerializer):
    class Meta:
        model = Teacher
        fields = ('id', 'user', 'subject')


class GradesSerializer(serializers.ModelSerializer):
    subject = SubjectSerializer(read_only=True)
    student = StudentSerializer(read_only=True)

    class Meta:

        model = Grade