From 32e62374506827723423471a115e6b25313ed887 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 10 Apr 2014 08:45:48 -0400 Subject: [PATCH] [1.7.x] Fixed #22195 -- Used constants to define built-in tags for check framework. Thanks Elvard for the patch. Backport of b513fa5fc6 from master --- django/contrib/admin/apps.py | 2 +- django/contrib/auth/apps.py | 2 +- django/contrib/contenttypes/apps.py | 2 +- django/core/checks/__init__.py | 4 ++-- django/core/checks/compatibility/django_1_6_0.py | 4 ++-- django/core/checks/model_checks.py | 6 +++--- django/core/checks/registry.py | 10 ++++++++++ 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/django/contrib/admin/apps.py b/django/contrib/admin/apps.py index a1f4042998..3b4f1a3028 100644 --- a/django/contrib/admin/apps.py +++ b/django/contrib/admin/apps.py @@ -11,7 +11,7 @@ class SimpleAdminConfig(AppConfig): verbose_name = _("Administration") def ready(self): - checks.register('admin')(check_admin_app) + checks.register(checks.Tags.admin)(check_admin_app) class AdminConfig(SimpleAdminConfig): diff --git a/django/contrib/auth/apps.py b/django/contrib/auth/apps.py index f0e169c23c..254a73d3db 100644 --- a/django/contrib/auth/apps.py +++ b/django/contrib/auth/apps.py @@ -10,4 +10,4 @@ class AuthConfig(AppConfig): verbose_name = _("Authentication and Authorization") def ready(self): - checks.register('models')(check_user_model) + checks.register(checks.Tags.models)(check_user_model) diff --git a/django/contrib/contenttypes/apps.py b/django/contrib/contenttypes/apps.py index fbe4fccfa6..0462e3163c 100644 --- a/django/contrib/contenttypes/apps.py +++ b/django/contrib/contenttypes/apps.py @@ -9,4 +9,4 @@ class ContentTypesConfig(AppConfig): verbose_name = _("Content Types") def ready(self): - checks.register('models')(check_generic_foreign_keys) + checks.register(checks.Tags.models)(check_generic_foreign_keys) diff --git a/django/core/checks/__init__.py b/django/core/checks/__init__.py index 82a3acf337..cd4d5cebea 100644 --- a/django/core/checks/__init__.py +++ b/django/core/checks/__init__.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals from .messages import (CheckMessage, Debug, Info, Warning, Error, Critical, DEBUG, INFO, WARNING, ERROR, CRITICAL) -from .registry import register, run_checks, tag_exists +from .registry import register, run_checks, tag_exists, Tags # Import these to force registration of checks import django.core.checks.compatibility.django_1_6_0 # NOQA @@ -14,5 +14,5 @@ __all__ = [ 'CheckMessage', 'Debug', 'Info', 'Warning', 'Error', 'Critical', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', - 'register', 'run_checks', 'tag_exists', + 'register', 'run_checks', 'tag_exists', 'Tags', ] diff --git a/django/core/checks/compatibility/django_1_6_0.py b/django/core/checks/compatibility/django_1_6_0.py index 06fb113005..a805053aec 100644 --- a/django/core/checks/compatibility/django_1_6_0.py +++ b/django/core/checks/compatibility/django_1_6_0.py @@ -3,10 +3,10 @@ from __future__ import unicode_literals from django.apps import apps -from .. import Warning, register +from .. import Warning, register, Tags -@register('compatibility') +@register(Tags.compatibility) def check_1_6_compatibility(**kwargs): errors = [] errors.extend(_check_test_runner(**kwargs)) diff --git a/django/core/checks/model_checks.py b/django/core/checks/model_checks.py index 46e5c6ff94..3f5a36b41b 100644 --- a/django/core/checks/model_checks.py +++ b/django/core/checks/model_checks.py @@ -6,10 +6,10 @@ import types from django.apps import apps -from . import Error, register +from . import Error, Tags, register -@register('models') +@register(Tags.models) def check_all_models(app_configs=None, **kwargs): errors = [model.check(**kwargs) for model in apps.get_models() @@ -17,7 +17,7 @@ def check_all_models(app_configs=None, **kwargs): return list(chain(*errors)) -@register('models', 'signals') +@register(Tags.models, Tags.signals) def check_model_signals(app_configs=None, **kwargs): """Ensure lazily referenced model signals senders are installed.""" from django.db import models diff --git a/django/core/checks/registry.py b/django/core/checks/registry.py index 21efbf317e..e88e0b8c37 100644 --- a/django/core/checks/registry.py +++ b/django/core/checks/registry.py @@ -6,6 +6,16 @@ from itertools import chain from django.utils.itercompat import is_iterable +class Tags(object): + """ + Built-in tags for internal checks. + """ + admin = 'admin' + compatibility = 'compatibility' + models = 'models' + signals = 'signals' + + class CheckRegistry(object): def __init__(self):