Skip to content

Commit

Permalink
Got rid of unnecessary imports , adjusted serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSychev2005 committed Oct 12, 2024
1 parent 7387a51 commit e8cfbee
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
13 changes: 1 addition & 12 deletions BackEnd/administration/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from collections import defaultdict

from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from rest_framework import serializers
from authentication.models import CustomUser
from profiles.models import (
Expand All @@ -10,7 +7,6 @@
)
from utils.administration.create_password import generate_password
from utils.administration.send_email import send_email_about_admin_registration
from validation.validate_password import validate_password_long
from .models import AutoModeration, ModerationEmail

User = get_user_model()
Expand All @@ -31,25 +27,18 @@ class AdminRegistrationSerializer(serializers.Serializer):
)

def validate(self, value):
custom_errors = defaultdict(list)
email = value.get("email").lower()

if User.objects.filter(email=email).exists():
custom_errors["email"].append("Email is already registered")
raise serializers.ValidationError("Email is already registered")

if custom_errors:
raise serializers.ValidationError(custom_errors)
return value

def create(self, validated_data):
email = validated_data.get("email")
password = generate_password()
name = "admin"
surname = "admin"
admin = User.objects.create(
email=email,
name=name,
surname=surname,
is_staff=True,
is_active=True,
)
Expand Down
2 changes: 0 additions & 2 deletions BackEnd/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from administration.models import AutoModeration, ModerationEmail
from authentication.models import CustomUser
from profiles.models import Profile
from utils.administration.create_password import generate_password
from utils.administration.send_email import send_email_about_admin_registration
from .permissions import IsStaffUser, IsStaffUserOrReadOnly, IsSuperUser


Expand Down

0 comments on commit e8cfbee

Please sign in to comment.