Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
239133e3
Commit
239133e3
authored
Feb 02, 2016
by
Skia
Browse files
Fix generate_username for accents
parent
6b81210b
Changes
1
Hide whitespace changes
Inline
Side-by-side
core/models.py
View file @
239133e3
...
...
@@ -8,6 +8,8 @@ from django.core.urlresolvers import reverse
from
django.conf
import
settings
from
datetime
import
datetime
,
timedelta
import
unicodedata
class
Group
(
AuthGroup
):
def
get_absolute_url
(
self
):
"""
...
...
@@ -134,7 +136,10 @@ class User(AbstractBaseUser, PermissionsMixin):
For example: Guy Carlier gives gcarlier, and gcarlier1 if the first one exists
Returns the generated username
"""
user_name
=
str
(
self
.
first_name
[
0
]
+
self
.
last_name
).
lower
()
def
remove_accents
(
data
):
return
''
.
join
(
x
for
x
in
unicodedata
.
normalize
(
'NFKD'
,
data
)
if
\
unicodedata
.
category
(
x
)[
0
]
==
'L'
).
lower
()
user_name
=
remove_accents
(
self
.
first_name
[
0
]
+
self
.
last_name
).
encode
(
'ascii'
,
'ignore'
).
decode
(
'utf-8'
)
un_set
=
[
u
.
username
for
u
in
User
.
objects
.
all
()]
if
user_name
in
un_set
:
i
=
1
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment