You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

apps.py 1.1KB

5 years ago
12345678910111213141516171819202122232425262728
  1. from django.apps import AppConfig
  2. from django.core import checks
  3. from django.db.models.query_utils import DeferredAttribute
  4. from django.db.models.signals import post_migrate
  5. from django.utils.translation import gettext_lazy as _
  6. from . import get_user_model
  7. from .checks import check_models_permissions, check_user_model
  8. from .management import create_permissions
  9. from .signals import user_logged_in
  10. class AuthConfig(AppConfig):
  11. name = 'django.contrib.auth'
  12. verbose_name = _("Authentication and Authorization")
  13. def ready(self):
  14. post_migrate.connect(
  15. create_permissions,
  16. dispatch_uid="django.contrib.auth.management.create_permissions"
  17. )
  18. last_login_field = getattr(get_user_model(), 'last_login', None)
  19. # Register the handler only if UserModel.last_login is a field.
  20. if isinstance(last_login_field, DeferredAttribute):
  21. from .models import update_last_login
  22. user_logged_in.connect(update_last_login, dispatch_uid='update_last_login')
  23. checks.register(check_user_model, checks.Tags.models)
  24. checks.register(check_models_permissions, checks.Tags.models)