diff options
| author | averybigant <averybigant@gmail.com> | 2014-11-05 14:01:49 +0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-11-11 16:29:32 +0100 |
| commit | b7a5b6ab8672daf907ba57e50edbed4cad596d4b (patch) | |
| tree | abd0bf721e3ea3df856aa8a358c96d69787177b4 /django | |
| parent | b3fd39f7c8921b314f12dd53ee65740464d4a5f1 (diff) | |
Fixed #23750 -- Allowed core.checks.register to be used as a function
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/apps.py | 2 | ||||
| -rw-r--r-- | django/contrib/auth/apps.py | 2 | ||||
| -rw-r--r-- | django/contrib/contenttypes/apps.py | 2 | ||||
| -rw-r--r-- | django/core/checks/registry.py | 17 |
4 files changed, 15 insertions, 8 deletions
diff --git a/django/contrib/admin/apps.py b/django/contrib/admin/apps.py index 3b4f1a3028..b052746ff4 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(checks.Tags.admin)(check_admin_app) + checks.register(check_admin_app, checks.Tags.admin) class AdminConfig(SimpleAdminConfig): diff --git a/django/contrib/auth/apps.py b/django/contrib/auth/apps.py index 254a73d3db..3a0cb1aea1 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(checks.Tags.models)(check_user_model) + checks.register(check_user_model, checks.Tags.models) diff --git a/django/contrib/contenttypes/apps.py b/django/contrib/contenttypes/apps.py index 0462e3163c..6fc8633762 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(checks.Tags.models)(check_generic_foreign_keys) + checks.register(check_generic_foreign_keys, checks.Tags.models) diff --git a/django/core/checks/registry.py b/django/core/checks/registry.py index e8626f03c7..88cc519a50 100644 --- a/django/core/checks/registry.py +++ b/django/core/checks/registry.py @@ -23,11 +23,11 @@ class CheckRegistry(object): self.registered_checks = [] self.deployment_checks = [] - def register(self, *tags, **kwargs): + def register(self, check=None, *tags, **kwargs): """ - Decorator. Register given function `f` labeled with given `tags`. The - function should receive **kwargs and return list of Errors and - Warnings. + Can be used as a function or a decorator. Register given function + `f` labeled with given `tags`. The function should receive **kwargs + and return list of Errors and Warnings. Example:: @@ -36,6 +36,8 @@ class CheckRegistry(object): def my_check(apps, **kwargs): # ... perform checks and collect `errors` ... return errors + # or + registry.register(my_check, 'mytag', 'anothertag') """ kwargs.setdefault('deploy', False) @@ -49,7 +51,12 @@ class CheckRegistry(object): self.registered_checks.append(check) return check - return inner + if callable(check): + return inner(check) + else: + if check: + tags += (check, ) + return inner def run_checks(self, app_configs=None, tags=None, include_deployment_checks=False): """ Run all registered checks and return list of Errors and Warnings. |
