Statistics
| Branch: | Tag: | Revision:

root / monkey_patch / models.py @ 2a2ea58f

History | View | Annotate | Download (826 Bytes)

1
from django.utils.translation import ugettext as _
2
from django.db.models.signals import class_prepared
3
from django.core.validators import MaxLengthValidator
4
from flowspy.monkey_patch import MAX_USERNAME_LENGTH
5

    
6
def longer_username(sender, *args, **kwargs):
7
    if sender.__name__ == "User" and sender.__module__ == "django.contrib.auth.models":
8
        sender._meta.get_field("username").max_length = MAX_USERNAME_LENGTH()
9
        # For Django 1.2 to work, the validator has to be declared apart from max_length
10
        sender._meta.get_field("username").validators = [MaxLengthValidator(MAX_USERNAME_LENGTH())]
11
        sender._meta.get_field("username").help_text = _("Required, %s characters or fewer. Only letters, numbers, and @, ., +, -, or _ characters." % MAX_USERNAME_LENGTH())
12
class_prepared.connect(longer_username)