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
0490d72f
Kaydet (Commit)
0490d72f
authored
Ara 10, 2015
tarafından
Vincenzo Pandolfo
Kaydeden (comit)
Tim Graham
Ock 22, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24116 -- Moved AdminSite.check_dependencies() to system checks.
üst
956cde80
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
39 deletions
+93
-39
apps.py
django/contrib/admin/apps.py
+2
-1
checks.py
django/contrib/admin/checks.py
+43
-0
sites.py
django/contrib/admin/sites.py
+0
-38
checks.txt
docs/ref/checks.txt
+10
-0
tests.py
tests/admin_checks/tests.py
+38
-0
No files found.
django/contrib/admin/apps.py
Dosyayı görüntüle @
0490d72f
from
django.apps
import
AppConfig
from
django.contrib.admin.checks
import
check_admin_app
from
django.contrib.admin.checks
import
check_admin_app
,
check_dependencies
from
django.core
import
checks
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -11,6 +11,7 @@ class SimpleAdminConfig(AppConfig):
verbose_name
=
_
(
"Administration"
)
def
ready
(
self
):
checks
.
register
(
check_dependencies
,
checks
.
Tags
.
admin
)
checks
.
register
(
check_admin_app
,
checks
.
Tags
.
admin
)
...
...
django/contrib/admin/checks.py
Dosyayı görüntüle @
0490d72f
...
...
@@ -3,6 +3,8 @@ from __future__ import unicode_literals
from
itertools
import
chain
from
django.apps
import
apps
from
django.conf
import
settings
from
django.contrib.admin.utils
import
(
NotRelationField
,
flatten
,
get_fields_from_path
,
)
...
...
@@ -12,6 +14,7 @@ from django.db import models
from
django.forms.models
import
(
BaseModelForm
,
BaseModelFormSet
,
_get_foreign_key
,
)
from
django.template.engine
import
Engine
def
check_admin_app
(
**
kwargs
):
...
...
@@ -20,6 +23,46 @@ def check_admin_app(**kwargs):
return
system_check_errors
def
check_dependencies
(
**
kwargs
):
"""
Check that the admin's dependencies are correctly installed.
"""
errors
=
[]
# contrib.contenttypes must be installed.
if
not
apps
.
is_installed
(
'django.contrib.contenttypes'
):
missing_app
=
checks
.
Error
(
"'django.contrib.contenttypes' must be in INSTALLED_APPS in order "
"to use the admin application."
,
id
=
"admin.E401"
,
)
errors
.
append
(
missing_app
)
# The auth context processor must be installed if using the default
# authentication backend.
try
:
default_template_engine
=
Engine
.
get_default
()
except
Exception
:
# Skip this non-critical check:
# 1. if the user has a non-trivial TEMPLATES setting and Django
# can't find a default template engine
# 2. if anything goes wrong while loading template engines, in
# order to avoid raising an exception from a confusing location
# Catching ImproperlyConfigured suffices for 1. but 2. requires
# catching all exceptions.
pass
else
:
if
(
'django.contrib.auth.context_processors.auth'
not
in
default_template_engine
.
context_processors
and
'django.contrib.auth.backends.ModelBackend'
in
settings
.
AUTHENTICATION_BACKENDS
):
missing_template
=
checks
.
Error
(
"'django.contrib.auth.context_processors.auth' must be in "
"TEMPLATES in order to use the admin application."
,
id
=
"admin.E402"
)
errors
.
append
(
missing_template
)
return
errors
class
BaseModelAdminChecks
(
object
):
def
check
(
self
,
admin_obj
,
**
kwargs
):
...
...
django/contrib/admin/sites.py
Dosyayı görüntüle @
0490d72f
...
...
@@ -7,7 +7,6 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
from
django.core.exceptions
import
ImproperlyConfigured
,
PermissionDenied
from
django.db.models.base
import
ModelBase
from
django.http
import
Http404
,
HttpResponseRedirect
from
django.template.engine
import
Engine
from
django.template.response
import
TemplateResponse
from
django.urls
import
NoReverseMatch
,
reverse
from
django.utils
import
six
...
...
@@ -172,40 +171,6 @@ class AdminSite(object):
"""
return
request
.
user
.
is_active
and
request
.
user
.
is_staff
def
check_dependencies
(
self
):
"""
Check that all things needed to run the admin have been correctly installed.
The default implementation checks that admin and contenttypes apps are
installed, as well as the auth context processor.
"""
if
not
apps
.
is_installed
(
'django.contrib.admin'
):
raise
ImproperlyConfigured
(
"Put 'django.contrib.admin' in your INSTALLED_APPS "
"setting in order to use the admin application."
)
if
not
apps
.
is_installed
(
'django.contrib.contenttypes'
):
raise
ImproperlyConfigured
(
"Put 'django.contrib.contenttypes' in your INSTALLED_APPS "
"setting in order to use the admin application."
)
try
:
default_template_engine
=
Engine
.
get_default
()
except
Exception
:
# Skip this non-critical check:
# 1. if the user has a non-trivial TEMPLATES setting and Django
# can't find a default template engine
# 2. if anything goes wrong while loading template engines, in
# order to avoid raising an exception from a confusing location
# Catching ImproperlyConfigured suffices for 1. but 2. requires
# catching all exceptions.
pass
else
:
if
(
'django.contrib.auth.context_processors.auth'
not
in
default_template_engine
.
context_processors
):
raise
ImproperlyConfigured
(
"Enable 'django.contrib.auth.context_processors.auth' "
"in your TEMPLATES setting in order to use the admin "
"application."
)
def
admin_view
(
self
,
view
,
cacheable
=
False
):
"""
Decorator to create an admin view attached to this ``AdminSite``. This
...
...
@@ -257,9 +222,6 @@ class AdminSite(object):
# and django.contrib.contenttypes.views imports ContentType.
from
django.contrib.contenttypes
import
views
as
contenttype_views
if
settings
.
DEBUG
:
self
.
check_dependencies
()
def
wrap
(
view
,
cacheable
=
False
):
def
wrapper
(
*
args
,
**
kwargs
):
return
self
.
admin_view
(
view
,
cacheable
)(
*
args
,
**
kwargs
)
...
...
docs/ref/checks.txt
Dosyayı görüntüle @
0490d72f
...
...
@@ -409,6 +409,16 @@ registered as an inline on a :class:`~django.contrib.admin.ModelAdmin`.
* **admin.E304**: ``<model>`` has no ``GenericForeignKey`` using content type
field ``<field name>`` and object ID field ``<field name>``.
AdminSite
~~~~~~~~~
The following checks are performed on the default
:class:`~django.contrib.admin.AdminSite`:
* **admin.E401**: :mod:`django.contrib.contenttypes` must be in
:setting:`INSTALLED_APPS` in order to use the admin application.
* **admin.E402**: :mod:`django.contrib.auth.context_processors.auth`
must be in :setting:`TEMPLATES` in order to use the admin application.
Auth
----
...
...
tests/admin_checks/tests.py
Dosyayı görüntüle @
0490d72f
...
...
@@ -54,6 +54,44 @@ class SystemChecksTestCase(SimpleTestCase):
admin
.
site
.
unregister
(
Song
)
admin
.
sites
.
system_check_errors
=
[]
@override_settings
(
INSTALLED_APPS
=
[
'django.contrib.admin'
])
def
test_contenttypes_dependency
(
self
):
errors
=
admin
.
checks
.
check_dependencies
()
expected
=
[
checks
.
Error
(
"'django.contrib.contenttypes' must be in "
"INSTALLED_APPS in order to use the admin application."
,
id
=
"admin.E401"
,
)
]
self
.
assertEqual
(
errors
,
expected
)
@override_settings
(
INSTALLED_APPS
=
[
'django.contrib.admin'
,
'django.contrib.auth'
,
'django.contrib.contenttypes'
,
],
TEMPLATES
=
[{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
:
[],
'APP_DIRS'
:
True
,
'OPTIONS'
:
{
'context_processors'
:
[],
},
}],
)
def
test_auth_contextprocessor_dependency
(
self
):
errors
=
admin
.
checks
.
check_dependencies
()
expected
=
[
checks
.
Error
(
"'django.contrib.auth.context_processors.auth' must be in "
"TEMPLATES in order to use the admin application."
,
id
=
"admin.E402"
,
)
]
self
.
assertEqual
(
errors
,
expected
)
@override_settings
(
DEBUG
=
True
)
def
test_custom_adminsite
(
self
):
class
CustomAdminSite
(
admin
.
AdminSite
):
...
...
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