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
99d4fc18
Kaydet (Commit)
99d4fc18
authored
Eki 15, 2018
tarafından
Jon Dufresne
Kaydeden (comit)
Tim Graham
Eki 15, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27829 -- Added warning for settings.DEFAULT_CONTENT_TYPE usage outside of Django.
üst
1299421c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
4 deletions
+36
-4
__init__.py
django/conf/__init__.py
+20
-2
test_default_content_type.py
tests/view_tests/tests/test_default_content_type.py
+16
-2
No files found.
django/conf/__init__.py
Dosyayı görüntüle @
99d4fc18
...
...
@@ -9,9 +9,11 @@ for a list of all possible variables.
import
importlib
import
os
import
time
import
traceback
import
warnings
from
pathlib
import
Path
import
django
from
django.conf
import
global_settings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.utils.deprecation
import
RemovedInDjango30Warning
...
...
@@ -19,6 +21,8 @@ from django.utils.functional import LazyObject, empty
ENVIRONMENT_VARIABLE
=
"DJANGO_SETTINGS_MODULE"
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG
=
'The DEFAULT_CONTENT_TYPE setting is deprecated.'
class
LazySettings
(
LazyObject
):
"""
...
...
@@ -93,6 +97,20 @@ class LazySettings(LazyObject):
"""Return True if the settings have already been configured."""
return
self
.
_wrapped
is
not
empty
@property
def
DEFAULT_CONTENT_TYPE
(
self
):
stack
=
traceback
.
extract_stack
()
# Show a warning if the setting is used outside of Django.
# Stack index: -1 this line, -2 the caller.
filename
,
_line_number
,
_function_name
,
_text
=
stack
[
-
2
]
if
not
filename
.
startswith
(
os
.
path
.
dirname
(
django
.
__file__
)):
warnings
.
warn
(
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG
,
RemovedInDjango30Warning
,
stacklevel
=
2
,
)
return
self
.
__getattr__
(
'DEFAULT_CONTENT_TYPE'
)
class
Settings
:
def
__init__
(
self
,
settings_module
):
...
...
@@ -126,7 +144,7 @@ class Settings:
raise
ImproperlyConfigured
(
"The SECRET_KEY setting must not be empty."
)
if
self
.
is_overridden
(
'DEFAULT_CONTENT_TYPE'
):
warnings
.
warn
(
'The DEFAULT_CONTENT_TYPE setting is deprecated.'
,
RemovedInDjango30Warning
)
warnings
.
warn
(
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG
,
RemovedInDjango30Warning
)
if
hasattr
(
time
,
'tzset'
)
and
self
.
TIME_ZONE
:
# When we can, attempt to validate the timezone. If we can't find
...
...
@@ -172,7 +190,7 @@ class UserSettingsHolder:
def
__setattr__
(
self
,
name
,
value
):
self
.
_deleted
.
discard
(
name
)
if
name
==
'DEFAULT_CONTENT_TYPE'
:
warnings
.
warn
(
'The DEFAULT_CONTENT_TYPE setting is deprecated.'
,
RemovedInDjango30Warning
)
warnings
.
warn
(
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG
,
RemovedInDjango30Warning
)
super
()
.
__setattr__
(
name
,
value
)
def
__delattr__
(
self
,
name
):
...
...
tests/view_tests/tests/test_default_content_type.py
Dosyayı görüntüle @
99d4fc18
import
sys
from
types
import
ModuleType
from
django.conf
import
S
ettings
from
django.conf
import
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG
,
Settings
,
s
ettings
from
django.test
import
SimpleTestCase
,
ignore_warnings
from
django.utils.deprecation
import
RemovedInDjango30Warning
class
DefaultContentTypeTests
(
SimpleTestCase
):
msg
=
'The DEFAULT_CONTENT_TYPE setting is deprecated.'
msg
=
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG
@ignore_warnings
(
category
=
RemovedInDjango30Warning
)
def
test_default_content_type_is_text_html
(
self
):
...
...
@@ -42,3 +42,17 @@ class DefaultContentTypeTests(SimpleTestCase):
Settings
(
'fake_settings_module'
)
finally
:
del
sys
.
modules
[
'fake_settings_module'
]
def
test_access_warning
(
self
):
with
self
.
assertRaisesMessage
(
RemovedInDjango30Warning
,
self
.
msg
):
settings
.
DEFAULT_CONTENT_TYPE
# Works a second time.
with
self
.
assertRaisesMessage
(
RemovedInDjango30Warning
,
self
.
msg
):
settings
.
DEFAULT_CONTENT_TYPE
@ignore_warnings
(
category
=
RemovedInDjango30Warning
)
def
test_access
(
self
):
with
self
.
settings
(
DEFAULT_CONTENT_TYPE
=
'text/xml'
):
self
.
assertEqual
(
settings
.
DEFAULT_CONTENT_TYPE
,
'text/xml'
)
# Works a second time.
self
.
assertEqual
(
settings
.
DEFAULT_CONTENT_TYPE
,
'text/xml'
)
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