Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
b7a5b6ab
Kaydet (Commit)
b7a5b6ab
authored
Kas 05, 2014
tarafından
averybigant
Kaydeden (comit)
Tim Graham
Kas 11, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #23750 -- Allowed core.checks.register to be used as a function
üst
b3fd39f7
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
71 additions
and
14 deletions
+71
-14
AUTHORS
AUTHORS
+1
-0
apps.py
django/contrib/admin/apps.py
+1
-1
apps.py
django/contrib/auth/apps.py
+1
-1
apps.py
django/contrib/contenttypes/apps.py
+1
-1
registry.py
django/core/checks/registry.py
+12
-5
1.8.txt
docs/releases/1.8.txt
+5
-0
checks.txt
docs/topics/checks.txt
+14
-0
tests.py
tests/check_framework/tests.py
+36
-6
No files found.
AUTHORS
Dosyayı görüntüle @
b7a5b6ab
...
...
@@ -561,6 +561,7 @@ answer newbie questions, and generally made Django that much better:
Raúl Cumplido <raulcumplido@gmail.com>
Remco Wendt <remco.wendt@gmail.com>
Renaud Parent <renaud.parent@gmail.com>
Renbi Yu <averybigant@gmail.com>
Reza Mohammadi <reza@zeerak.ir>
rhettg@gmail.com
Ricardo Javier Cárdenes Medina <ricardo.cardenes@gmail.com>
...
...
django/contrib/admin/apps.py
Dosyayı görüntüle @
b7a5b6ab
...
...
@@ -11,7 +11,7 @@ class SimpleAdminConfig(AppConfig):
verbose_name
=
_
(
"Administration"
)
def
ready
(
self
):
checks
.
register
(
check
s
.
Tags
.
admin
)(
check_admin_app
)
checks
.
register
(
check
_admin_app
,
checks
.
Tags
.
admin
)
class
AdminConfig
(
SimpleAdminConfig
):
...
...
django/contrib/auth/apps.py
Dosyayı görüntüle @
b7a5b6ab
...
...
@@ -10,4 +10,4 @@ class AuthConfig(AppConfig):
verbose_name
=
_
(
"Authentication and Authorization"
)
def
ready
(
self
):
checks
.
register
(
check
s
.
Tags
.
models
)(
check_user_model
)
checks
.
register
(
check
_user_model
,
checks
.
Tags
.
models
)
django/contrib/contenttypes/apps.py
Dosyayı görüntüle @
b7a5b6ab
...
...
@@ -9,4 +9,4 @@ class ContentTypesConfig(AppConfig):
verbose_name
=
_
(
"Content Types"
)
def
ready
(
self
):
checks
.
register
(
check
s
.
Tags
.
models
)(
check_generic_foreign_key
s
)
checks
.
register
(
check
_generic_foreign_keys
,
checks
.
Tags
.
model
s
)
django/core/checks/registry.py
Dosyayı görüntüle @
b7a5b6ab
...
...
@@ -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.
...
...
docs/releases/1.8.txt
Dosyayı görüntüle @
b7a5b6ab
...
...
@@ -364,6 +364,11 @@ Signals
the request, was added to the :data:`~django.core.signals.request_started`
signal.
System Check Framework
^^^^^^^^^^^^^^^^^^^^^^
* :attr:`~django.core.checks.register` can now be used as a function.
Templates
^^^^^^^^^
...
...
docs/topics/checks.txt
Dosyayı görüntüle @
b7a5b6ab
...
...
@@ -151,6 +151,20 @@ settings file like this::
These checks will only be run if the :djadminopt:`--deploy` option is passed to
the :djadmin:`check` command.
You can also use ``register`` as a function rather than a decorator by
passing a callable object (usually a function) as the first argument
to ``register``.
The code below is equivalent to the code above::
def my_check(app_configs, **kwargs):
...
register(my_check, Tags.security, deploy=True)
.. versionchanged:: 1.8
The ability to use register as a function was added.
.. _field-checking:
Field, Model, and Manager checks
...
...
tests/check_framework/tests.py
Dosyayı görüntüle @
b7a5b6ab
...
...
@@ -31,17 +31,47 @@ class DummyObj(object):
class
SystemCheckFrameworkTests
(
TestCase
):
def
test_register_and_run_checks
(
self
):
calls
=
[
0
]
registry
=
CheckRegistry
()
@registry.register
()
def
f
(
**
kwargs
):
calls
[
0
]
+=
1
return
[
1
,
2
,
3
]
def
f2
(
**
kwargs
):
return
[
4
,
]
def
f3
(
**
kwargs
):
return
[
5
,
]
calls
=
[
0
]
# test register as decorator
registry
=
CheckRegistry
()
registry
.
register
()(
f
)
registry
.
register
(
"tag1"
,
"tag2"
)(
f2
)
registry
.
register
(
"tag2"
,
deploy
=
True
)(
f3
)
# test register as function
registry2
=
CheckRegistry
()
registry2
.
register
(
f
)
registry2
.
register
(
f2
,
"tag1"
,
"tag2"
)
registry2
.
register
(
f3
,
"tag2"
,
deploy
=
True
)
# check results
errors
=
registry
.
run_checks
()
self
.
assertEqual
(
errors
,
[
1
,
2
,
3
])
self
.
assertEqual
(
calls
[
0
],
1
)
errors2
=
registry2
.
run_checks
()
self
.
assertEqual
(
errors
,
errors2
)
self
.
assertEqual
(
sorted
(
errors
),
[
1
,
2
,
3
,
4
])
self
.
assertEqual
(
calls
[
0
],
2
)
errors
=
registry
.
run_checks
(
tags
=
[
"tag1"
])
errors2
=
registry2
.
run_checks
(
tags
=
[
"tag1"
])
self
.
assertEqual
(
errors
,
errors2
)
self
.
assertEqual
(
sorted
(
errors
),
[
4
])
errors
=
registry
.
run_checks
(
tags
=
[
"tag1"
,
"tag2"
],
include_deployment_checks
=
True
)
errors2
=
registry2
.
run_checks
(
tags
=
[
"tag1"
,
"tag2"
],
include_deployment_checks
=
True
)
self
.
assertEqual
(
errors
,
errors2
)
self
.
assertEqual
(
sorted
(
errors
),
[
4
,
5
])
class
MessageTests
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment