pandora/pandora/app/monkey_patch.py

35 lines
798 B
Python
Raw Normal View History

2013-05-20 15:06:48 +00:00
# -*- coding: utf-8 -*-
2018-07-29 20:12:56 +00:00
from django.contrib.auth import get_user_model
2018-07-29 20:28:46 +00:00
from django.contrib.auth.models import Group
2018-07-29 20:12:56 +00:00
2013-05-20 15:06:48 +00:00
from django.core.validators import MaxLengthValidator
2018-07-29 20:12:56 +00:00
User = get_user_model()
# load config from json
from . import config
2013-05-20 15:06:48 +00:00
config.init()
NEW_LENGTH = {
'username': 255,
'email': 255,
'password': 255,
}
def monkey_patch_username():
for field in NEW_LENGTH:
f = User._meta.get_field(field)
f.max_length = NEW_LENGTH[field]
for v in f.validators:
if isinstance(v, MaxLengthValidator):
v.limit_value = NEW_LENGTH[field]
f = Group._meta.get_field('name')
f.max_length = 255
for v in f.validators:
if isinstance(v, MaxLengthValidator):
v.limit_value = 255
monkey_patch_username()