Merge branch 'feature/auto-username' into develop

# Conflicts:
#	apps/utils/methods.py
This commit is contained in:
Kuroshini 2020-01-14 22:01:57 +03:00
commit 24f0c25a3d
2 changed files with 15 additions and 9 deletions

View File

@ -43,11 +43,6 @@ class SignupSerializer(serializers.ModelSerializer):
if account_models.User.objects.filter(username__iexact=value).exists():
raise serializers.ValidationError()
else:
value = utils_methods.username_random()
while account_models.User.objects.filter(username__iexact=value).exists():
value = utils_methods.username_random()
return value
def validate_email(self, value):
@ -67,6 +62,13 @@ class SignupSerializer(serializers.ModelSerializer):
def create(self, validated_data):
"""Overridden create method"""
username = validated_data.get('username')
if not username:
username = utils_methods.username_random()
while account_models.User.objects.filter(username__iexact=username).exists():
username = utils_methods.username_random()
obj = account_models.User.objects.make(
username=validated_data.get('username'),
password=validated_data.get('password'),

View File

@ -5,8 +5,6 @@ import re
import string
from collections import namedtuple
from io import BytesIO
from PIL import Image
import requests
from django.conf import settings
@ -14,6 +12,7 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.gis.geos import Point
from django.http.request import HttpRequest
from django.utils.timezone import datetime
from PIL import Image
from rest_framework import status
from rest_framework.request import Request
@ -58,9 +57,14 @@ def username_validator(username: str) -> bool:
def username_random():
"""Generate random username"""
return '{letters}{digits}'.format(
letters=''.join([random.choice(string.ascii_lowercase) for _ in range(5)]),
username = list('{letters}{digits}'.format(
letters=''.join([random.choice(string.ascii_lowercase) for _ in range(4)]),
digits=random.randrange(100, 1000)
))
random.shuffle(username)
return '{first}{username}'.format(
first=random.choice(string.ascii_lowercase),
username=''.join(username)
)