diff --git a/accounts/forms.py b/accounts/forms.py index 4a140777..edd06042 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- import re import json +import string import ast +from random import choice from django import forms from django.contrib.auth.forms import ReadOnlyPasswordHashField from django.forms.util import ErrorList @@ -207,7 +209,7 @@ class RegistrationCompleteForm(forms.ModelForm): country = forms.ModelChoiceField(label=_(u'Страна'), queryset=Country.objects.all(), widget=forms.Select(attrs={'class': 'select2'})) city = forms.CharField(label=_(u'Город'), widget=forms.HiddenInput()) - url = forms.CharField(widget=forms.TextInput(attrs={'placeholder': _(u'url(обязательно)')})) + url = forms.CharField(widget=forms.TextInput(), required=False) # code_country = forms.ChoiceField(label=_(u'код страны'), initial='70', # choices=[(str(c.phone_code), '+' + str(c.phone_code)) for c in @@ -245,15 +247,34 @@ class RegistrationCompleteForm(forms.ModelForm): valid = url_regex.match(url) if valid is None: raise forms.ValidationError(_(u'url должен состоять только из латинских букв и цифр')) + if not url: + return self.make_url() + elif not self.check_url(url): + raise forms.ValidationError(_(u'Пользователь с таким url уже существует')) + return url + def check_url(self, url): try: User.objects.get(url=url) - User.objects.get(id=int(url)) except (User.DoesNotExist,): - return url - except (ValueError, ): pass - raise forms.ValidationError(_(u'Пользователь с таким url уже существует')) + else: + return False + try: + User.objects.get(id=int(url)) + except (ValueError, User.DoesNotExist,): + return True + else: + return False + + def make_url(self, url=None): + if url is None: + url = 'id{pk}'.format(pk=self.instance.pk) + else: + url += choice(string.ascii_lowercase) + if not self.check_url(url): + return self.make_url(url) + return url class SocialRegistrationCompleteForm(RegistrationCompleteForm): diff --git a/templates/client/popups/register.html b/templates/client/popups/register.html index c7e50242..79a43a7d 100644 --- a/templates/client/popups/register.html +++ b/templates/client/popups/register.html @@ -6,7 +6,7 @@
{% trans 'Регистрация' %}
-
{% csrf_token %} + {% csrf_token %}
@@ -35,7 +35,7 @@
{% trans 'пароль должен иметь не меньше 6 символов' %}
-
+
diff --git a/templates/client/popups/user_information.html b/templates/client/popups/user_information.html index e8ae24ff..3326a32e 100644 --- a/templates/client/popups/user_information.html +++ b/templates/client/popups/user_information.html @@ -89,16 +89,19 @@ {% endcomment %} + {% trans "Укажите ниже желаемый адрес для Вашего профиля на Expomap" %} www.expomap.ru/
{{ form.url }}
-
ivanova
-
-
- +
+
{% trans 'например, ivanova' %}
+
+
+
+