Skip to content

Commit

Permalink
added new max_username_length property to app settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Silliman committed Aug 10, 2017
1 parent 3beb502 commit ff54c1f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions django_oneall/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

from django.conf import settings as django_settings

try:
from django.contrib.auth import get_user_model
except ImportError:
from django.db.models import get_user_model


class MissingOneAllSettings(KeyError):
def __init__(self, msg=None):
Expand Down Expand Up @@ -59,6 +64,20 @@ def store_user_info(self):
""" Whether to store personally identifiable information from users. Defaults to True. """
return bool(self._settings.get('store_user_info', True))

@property
def max_username_length(self):
""" Maximum length of pseudorandom username generated when store_user_info=False is set. Defaults to the max_length of the username field introspected by get_user_model)
Django 1.10 included a migration which updated the max_length of the username field from 30 to 150 chars. If you used django-oneall with older Django versions and are upgrading to Django>=1.10,
you will want to set the value of this to 30 (or whatever max_length your custom User model may have) so that your existing user accounts are not mis-identified
"""
user_model = get_user_model()
fld_len = user_model._meta.get_field('username').max_length
max_len = int(self._settings.get("max_username_length", fld_len))
if max_len > fld_len:
raise MissingOneAllSettings("OneAll setting 'max_username_length' is set to value %d, which is greater than the database field's length: %d" % (max_len, fld_len))
return max_len

@property
def token_expiration(self):
""" The amount of time an e-mail login token is valid for. """
Expand All @@ -71,4 +90,5 @@ def default_url(self):
return django_settings.LOGIN_REDIRECT_URL # Can be assumed to be set.



settings = AppSettings()

0 comments on commit ff54c1f

Please sign in to comment.