| author | ymh <ymh.work@gmail.com> |
| Sat, 28 Sep 2013 02:55:26 +0200 | |
| changeset 120 | 6ec0300b626e |
| parent 113 | c05567404888 |
| child 126 | a345f1a67bf1 |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
3 |
Created on Aug 4, 2013 |
|
4 |
||
5 |
@author: ymh |
|
6 |
''' |
|
7 |
from django.conf import settings |
|
8 |
from django.contrib.auth import get_user_model |
|
9 |
from django.contrib.auth.forms import (UserChangeForm as AuthUserChangeForm, |
|
10 |
UserCreationForm as AuthUserCreationForm) |
|
11 |
from django.core.exceptions import ValidationError |
|
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
from django.forms.fields import ChoiceField |
| 0 | 13 |
from django.utils.translation import ugettext as _ |
14 |
||
15 |
||
16 |
User = get_user_model() |
|
17 |
||
18 |
class UserCreationform(AuthUserCreationForm): |
|
19 |
class Meta: |
|
20 |
model = User |
|
21 |
||
22 |
def clean_username(self): |
|
23 |
# Since User.username is unique, this check is redundant, |
|
24 |
# but it sets a nicer error message than the ORM. See #13147. |
|
25 |
username = self.cleaned_data["username"] |
|
26 |
try: |
|
27 |
User.objects.get(username=username) |
|
28 |
except User.DoesNotExist: |
|
29 |
return username |
|
30 |
raise ValidationError(self.error_messages['duplicate_username']) |
|
31 |
||
32 |
||
33 |
class UserChangeForm(AuthUserChangeForm): |
|
34 |
language = ChoiceField(label=_("language"), choices=[(k,_(v)) for k,v in settings.LANGUAGES], initial=settings.LANGUAGE_CODE[:2]) |
|
35 |
class Meta: |
|
36 |
model = User |
|
| 4 | 37 |