Exemplo n.º 1
0
def long_username(sender, *args, **kwargs):
    """Override the built in username field"""
    if (sender.__name__ == "User" and
        sender.__module__ == "django.contrib.auth.models"):
        sender._meta.get_field("username").max_length = max_username_length()
        sender._meta.get_field("username").help_text = _("Required, %s "
            "characters or fewer. Only letters, numbers, and @, ., +, -, "
            "or _ characters." % max_username_length())
Exemplo n.º 2
0
def username_field():
    "return username field"
    return forms.RegexField(
            label=_("Username"), max_length=max_username_length(),
            regex=r'^[\w.@+-]+$',
            help_text=username_help(),
            error_messages={'invalid': _(
                "This value may contain only letters, numbers"
                " and @/./+/-/_ characters.")
            })
Exemplo n.º 3
0
def patch_username():
    username = User._meta.get_field("username")
    username.max_length = max_username_length()
    for v in username.validators:
        if isinstance(v, MaxLengthValidator):
            v.limit_value = max_username_length()
Exemplo n.º 4
0
 def forwards(self, orm):
     db.alter_column('auth_user', 'username', models.CharField(max_length=max_username_length()))
Exemplo n.º 5
0
def username_help():
    "username help text"
    return _("Required, %(chars)s characters or fewer."
            " Only letters, numbers, and characters "
            "such as @.+_- are allowed." %
            dict(chars=str(max_username_length())))