~netlandish/django-wiki

b72e9b7bf976c51ef4887fabe096d7e819d0b23b — Trevor Peacock 5 years ago cb45487
update minor change requests
3 files changed, 23 insertions(+), 7 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 +19 -3
@@ 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


@@ 18,9 36,7 @@ from wiki.core.diff import simple_merge
from wiki.core.plugins.base import PluginSettingsFormMixin
from wiki.editors import getEditor

from .forms_account_handling import (  # noqa: ignore=F401 importing additional forms here as a convenience for other modules expecting them here
    UserCreationForm, UserUpdateForm,
)
from .forms_account_handling import UserCreationForm, UserUpdateForm

validate_slug_numbers = RegexValidator(
    r'^[0-9]+$',

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