| 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 |
|
| 7 |
from . import get_user_model |
| 8 |
from .checks import check_middleware, check_models_permissions, check_user_model |
| 9 |
from .management import create_permissions |
| 10 |
from .signals import user_logged_in |
| 11 |
|
| 12 |
|
| 13 |
class AuthConfig(AppConfig): |
| 14 |
default_auto_field = "django.db.models.AutoField" |
| 15 |
name = "django.contrib.auth" |
| 16 |
verbose_name = _("Authentication and Authorization") |
| 17 |
|
| 18 |
def ready(self): |
| 19 |
post_migrate.connect( |
| 20 |
create_permissions, |
| 21 |
dispatch_uid="django.contrib.auth.management.create_permissions", |
| 22 |
) |
| 23 |
last_login_field = getattr(get_user_model(), "last_login", None) |
| 24 |
# Register the handler only if UserModel.last_login is a field. |
| 25 |
if isinstance(last_login_field, DeferredAttribute): |
| 26 |
from .models import update_last_login |
| 27 |
|
| 28 |
user_logged_in.connect(update_last_login, dispatch_uid="update_last_login") |
| 29 |
checks.register(check_user_model, checks.Tags.models) |
| 30 |
checks.register(check_models_permissions, checks.Tags.models) |
| 31 |
checks.register(check_middleware) |