fix_user_model: delay formatting of username field's help_text (fixes #7123)

% operator is encapsulated with allow_lazy from django.utils.functional.
This commit is contained in:
Benjamin Dauvergne 2015-05-01 14:26:12 +02:00
parent e7feeebc04
commit d2c6d42b97
1 changed files with 6 additions and 2 deletions

View File

@ -1,8 +1,12 @@
import re
from django.utils.translation import ugettext_lazy as _
from django.utils.functional import allow_lazy
from django.core.validators import MaxLengthValidator, RegexValidator
# Allow delaying formatting
uinterpolate= allow_lazy(lambda self, arg: self % arg, unicode)
#from django.db.models.signals import class_prepared
#def longer_username_signal(sender, *args, **kwargs):
# if (sender.__name__ == "User" and
@ -31,9 +35,9 @@ def patch_username(model):
return
field.max_length = MAX_USERNAME_LENGTH
field.help_text = _("Required, %s characters or fewer. Only letters, "
field.help_text = uinterpolate(_("Required, %s characters or fewer. Only letters, "
"numbers, and @, ., +, -, or _ "
"characters." % MAX_USERNAME_LENGTH)
"characters."), 255)
if app_settings.A2_USERNAME_HELP_TEXT:
field.help_text = app_settings.A2_USERNAME_HELP_TEXT
field.label = _('username')