~netlandish/django-wiki

fda2565e7778d3eaf010565d7a5a785c591b8239 — Trevor Peacock 5 years ago cb45487
update minor change requests
3 files changed, 22 insertions(+), 4 deletions(-)

M src/wiki/forms.py
M src/wiki/forms_account_handling.py
M tests/core/test_checks.py
M src/wiki/forms.py => src/wiki/forms.py +18 -0
@@ 1,3 1,21 @@

__all__ = [
    'UserCreationForm',
    'UserUpdateForm',
    'WikiSlugField',
    'SpamProtectionMixin',
    'CreateRootForm',
    'MoveForm',
    'EditForm',
    'SelectWidgetBootstrap',
    'TextInputPrepend',
    'CreateForm',
    'DeleteForm',
    'PermissionsForm',
    'DirFilterForm',
    'SearchForm',
]

from datetime import timedelta

from django import forms

M src/wiki/forms_account_handling.py => src/wiki/forms_account_handling.py +3 -3
@@ 21,18 21,18 @@ def _get_field(model, field):
User = get_user_model()


def check_user_field(user_model=User):
def check_user_field(user_model):
    return isinstance(_get_field(user_model, user_model.USERNAME_FIELD), CharField)


def check_email_field(user_model=User):
def check_email_field(user_model):
    return isinstance(_get_field(user_model, user_model.get_email_field_name()), EmailField)


# django parses the ModelForm (and Meta classes) on class creation, which fails with custom models without expected fields.
# We need to check this here, because if this module can't load then system checks can't run.
CustomUser = User \
    if (settings.ACCOUNT_HANDLING and check_user_field() and check_email_field()) \
    if (settings.ACCOUNT_HANDLING and check_user_field(User) and check_email_field(User)) \
    else django.contrib.auth.models.User



M tests/core/test_checks.py => tests/core/test_checks.py +1 -1
@@ 54,7 54,7 @@ class CheckTests(TestCase):
        from django.core.exceptions import FieldError
        from django import forms
        from ..testdata.models import VeryCustomUser
        with self.assertRaisesRegex(FieldError, 'Unknown field\(s\) \((email|username|, )+\) specified for VeryCustomUser'):
        with self.assertRaisesRegex(FieldError, 'Unknown field\\(s\\) \\((email|username|, )+\\) specified for VeryCustomUser'):
            class UserUpdateForm(forms.ModelForm):
                class Meta:
                    model = VeryCustomUser