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
f892781b
Kaydet (Commit)
f892781b
authored
Eki 27, 2018
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28606 -- Deprecated CachedStaticFilesStorage.
üst
55b0b766
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
58 additions
and
41 deletions
+58
-41
storage.py
django/contrib/staticfiles/storage.py
+9
-1
deprecation.txt
docs/internals/deprecation.txt
+3
-0
staticfiles.txt
docs/ref/contrib/staticfiles.txt
+10
-5
1.4.txt
docs/releases/1.4.txt
+1
-4
1.7.txt
docs/releases/1.7.txt
+1
-2
2.2.txt
docs/releases/2.2.txt
+4
-0
performance.txt
docs/topics/performance.txt
+3
-3
storage.py
tests/staticfiles_tests/storage.py
+4
-4
test_management.py
tests/staticfiles_tests/test_management.py
+2
-2
test_storage.py
tests/staticfiles_tests/test_storage.py
+20
-19
tests.py
tests/test_utils/tests.py
+1
-1
No files found.
django/contrib/staticfiles/storage.py
Dosyayı görüntüle @
f892781b
...
...
@@ -3,6 +3,7 @@ import json
import
os
import
posixpath
import
re
import
warnings
from
collections
import
OrderedDict
from
urllib.parse
import
unquote
,
urldefrag
,
urlsplit
,
urlunsplit
...
...
@@ -14,6 +15,7 @@ from django.core.cache import (
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.files.base
import
ContentFile
from
django.core.files.storage
import
FileSystemStorage
,
get_storage_class
from
django.utils.deprecation
import
RemovedInDjango31Warning
from
django.utils.functional
import
LazyObject
...
...
@@ -474,7 +476,13 @@ class CachedStaticFilesStorage(CachedFilesMixin, StaticFilesStorage):
A static file system storage backend which also saves
hashed copies of the files it saves.
"""
pass
def
__init__
(
self
,
*
args
,
**
kwargs
):
warnings
.
warn
(
'CachedStaticFilesStorage is deprecated in favor of '
'ManifestStaticFilesStorage.'
,
RemovedInDjango31Warning
,
stacklevel
=
2
,
)
super
()
.
__init__
(
*
args
,
**
kwargs
)
class
ManifestStaticFilesStorage
(
ManifestFilesMixin
,
StaticFilesStorage
):
...
...
docs/internals/deprecation.txt
Dosyayı görüntüle @
f892781b
...
...
@@ -26,6 +26,9 @@ details on these changes.
* The ``FILE_CHARSET`` setting will be removed.
* ``django.contrib.staticfiles.storage.CachedStaticFilesStorage`` will be
removed.
.. _deprecation-removed-in-3.0:
3.0
...
...
docs/ref/contrib/staticfiles.txt
Dosyayı görüntüle @
f892781b
...
...
@@ -62,7 +62,7 @@ The :djadmin:`collectstatic` management command calls the
method of the :setting:`STATICFILES_STORAGE` after each run and passes
a list of paths that have been found by the management command. It also
receives all command line options of :djadmin:`collectstatic`. This is used
by the :class:`~django.contrib.staticfiles.storage.
Cached
StaticFilesStorage`
by the :class:`~django.contrib.staticfiles.storage.
Manifest
StaticFilesStorage`
by default.
By default, collected files receive permissions from
...
...
@@ -229,9 +229,7 @@ local development, should **never be used in production** and is only
available if the :doc:`staticfiles </ref/contrib/staticfiles>` app is
in your project's :setting:`INSTALLED_APPS` setting.
``--insecure`` doesn't work with
:class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` or
:class:`~django.contrib.staticfiles.storage.CachedStaticFilesStorage`.
``--insecure`` doesn't work with :class:`~.storage.ManifestStaticFilesStorage`.
Example usage::
...
...
@@ -262,7 +260,7 @@ line options. It yields tuples of three values:
``processed`` is a boolean indicating whether or not the value was
post-processed, or an exception if post-processing failed.
The :class:`~django.contrib.staticfiles.storage.
Cached
StaticFilesStorage`
The :class:`~django.contrib.staticfiles.storage.
Manifest
StaticFilesStorage`
uses this behind the scenes to replace the paths with their hashed
counterparts and update the cache appropriately.
...
...
@@ -362,6 +360,13 @@ hashing algorithm.
.. class:: storage.CachedStaticFilesStorage
.. deprecated:: 2.1
``CachedStaticFilesStorage`` is deprecated as it has some intractable
problems, some of which are outlined below. Use
:class:`~storage.ManifestStaticFilesStorage` or a third-party cloud storage
instead.
``CachedStaticFilesStorage`` is a similar class like the
:class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` class
but uses Django's :doc:`caching framework</topics/cache>` for storing the
...
...
docs/releases/1.4.txt
Dosyayı görüntüle @
f892781b
...
...
@@ -466,15 +466,12 @@ files from a cloud service<staticfiles-from-cdn>`.
--------------------------------------------
The :mod:`staticfiles<django.contrib.staticfiles>` contrib app now has a
:class:`~django.contrib.staticfiles.storage.CachedStaticFilesStorage
` backend
``django.contrib.staticfiles.storage.CachedStaticFilesStorage`
` backend
that caches the files it saves (when running the :djadmin:`collectstatic`
management command) by appending the MD5 hash of the file's content to the
filename. For example, the file ``css/styles.css`` would also be saved as
``css/styles.55e7cbb9ba48.css``
See the :class:`~django.contrib.staticfiles.storage.CachedStaticFilesStorage`
docs for more information.
Simple clickjacking protection
------------------------------
...
...
docs/releases/1.7.txt
Dosyayı görüntüle @
f892781b
...
...
@@ -506,8 +506,7 @@ Minor features
and :attr:`~django.core.files.storage.FileSystemStorage.directory_permissions_mode`
parameters. See :djadmin:`collectstatic` for example usage.
* The :class:`~django.contrib.staticfiles.storage.CachedStaticFilesStorage`
backend gets a sibling class called
* The ``CachedStaticFilesStorage`` backend gets a sibling class called
:class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage`
that doesn't use the cache system at all but instead a JSON file called
``staticfiles.json`` for storing the mapping between the original file name
...
...
docs/releases/2.2.txt
Dosyayı görüntüle @
f892781b
...
...
@@ -354,3 +354,7 @@ Miscellaneous
* The ``FILE_CHARSET`` setting is deprecated. Starting with Django 3.1, files
read from disk must be UTF-8 encoded.
* ``django.contrib.staticfiles.storage.CachedStaticFilesStorage`` is
deprecated due to the intractable problems that is has. Use
:class:`.ManifestStaticFilesStorage` or a third-party cloud storage instead.
docs/topics/performance.txt
Dosyayı görüntüle @
f892781b
...
...
@@ -290,13 +290,13 @@ Static files
Static files, which by definition are not dynamic, make an excellent target for
optimization gains.
:class:`~django.contrib.staticfiles.storage.
Cached
StaticFilesStorage`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:class:`~django.contrib.staticfiles.storage.
Manifest
StaticFilesStorage`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~
By taking advantage of web browsers' caching abilities, you can
eliminate network hits entirely for a given file after the initial download.
:class:`~django.contrib.staticfiles.storage.
Cached
StaticFilesStorage` appends a
:class:`~django.contrib.staticfiles.storage.
Manifest
StaticFilesStorage` appends a
content-dependent tag to the filenames of :doc:`static files
</ref/contrib/staticfiles>` to make it safe for browsers to cache them
long-term without missing future changes - when a file changes, so will the
...
...
tests/staticfiles_tests/storage.py
Dosyayı görüntüle @
f892781b
...
...
@@ -2,7 +2,7 @@ import os
from
datetime
import
datetime
,
timedelta
from
django.conf
import
settings
from
django.contrib.staticfiles.storage
import
Cached
StaticFilesStorage
from
django.contrib.staticfiles.storage
import
Manifest
StaticFilesStorage
from
django.core.files
import
storage
from
django.utils
import
timezone
...
...
@@ -70,18 +70,18 @@ class QueryStringStorage(storage.Storage):
return
path
+
'?a=b&c=d'
class
Simple
CachedStaticFilesStorage
(
Cached
StaticFilesStorage
):
class
Simple
Storage
(
Manifest
StaticFilesStorage
):
def
file_hash
(
self
,
name
,
content
=
None
):
return
'deploy12345'
class
ExtraPatterns
CachedStaticFilesStorage
(
Cached
StaticFilesStorage
):
class
ExtraPatterns
Storage
(
Manifest
StaticFilesStorage
):
"""
A storage class to test pattern substitutions with more than one pattern
entry. The added pattern rewrites strings like "url(...)" to JS_URL("...").
"""
patterns
=
tuple
(
Cached
StaticFilesStorage
.
patterns
)
+
(
patterns
=
tuple
(
Manifest
StaticFilesStorage
.
patterns
)
+
(
(
"*.js"
,
(
(
r"""(url\(['"]{0,1}\s*(.*?)["']{0,1}\))"""
,
'JS_URL("
%
s")'
),
...
...
tests/staticfiles_tests/test_management.py
Dosyayı görüntüle @
f892781b
...
...
@@ -201,13 +201,13 @@ class TestCollectionVerbosity(CollectionTestCase):
self
.
assertIn
(
self
.
staticfiles_copied_msg
,
output
)
self
.
assertIn
(
self
.
copying_msg
,
output
)
@override_settings
(
STATICFILES_STORAGE
=
'django.contrib.staticfiles.storage.
Cached
StaticFilesStorage'
)
@override_settings
(
STATICFILES_STORAGE
=
'django.contrib.staticfiles.storage.
Manifest
StaticFilesStorage'
)
def
test_verbosity_1_with_post_process
(
self
):
stdout
=
StringIO
()
self
.
run_collectstatic
(
verbosity
=
1
,
stdout
=
stdout
,
post_process
=
True
)
self
.
assertNotIn
(
self
.
post_process_msg
,
stdout
.
getvalue
())
@override_settings
(
STATICFILES_STORAGE
=
'django.contrib.staticfiles.storage.
Cached
StaticFilesStorage'
)
@override_settings
(
STATICFILES_STORAGE
=
'django.contrib.staticfiles.storage.
Manifest
StaticFilesStorage'
)
def
test_verbosity_2_with_post_process
(
self
):
stdout
=
StringIO
()
self
.
run_collectstatic
(
verbosity
=
2
,
stdout
=
stdout
,
post_process
=
True
)
...
...
tests/staticfiles_tests/test_storage.py
Dosyayı görüntüle @
f892781b
...
...
@@ -12,7 +12,8 @@ from django.contrib.staticfiles.management.commands.collectstatic import (
)
from
django.core.cache.backends.base
import
BaseCache
from
django.core.management
import
call_command
from
django.test
import
override_settings
from
django.test
import
SimpleTestCase
,
ignore_warnings
,
override_settings
from
django.utils.deprecation
import
RemovedInDjango31Warning
from
.cases
import
CollectionTestCase
from
.settings
import
TEST_ROOT
...
...
@@ -43,9 +44,6 @@ class TestHashedFiles:
pass
def
test_template_tag_return
(
self
):
"""
Test the CachedStaticFilesStorage backend.
"""
self
.
assertStaticRaises
(
ValueError
,
"does/not/exist.png"
,
"/static/does/not/exist.png"
)
self
.
assertStaticRenders
(
"test/file.txt"
,
"/static/test/file.dad0999e4f8f.txt"
)
self
.
assertStaticRenders
(
"test/file.txt"
,
"/static/test/file.dad0999e4f8f.txt"
,
asvar
=
True
)
...
...
@@ -232,6 +230,7 @@ class TestHashedFiles:
self
.
assertPostCondition
()
@ignore_warnings
(
category
=
RemovedInDjango31Warning
)
@override_settings
(
STATICFILES_STORAGE
=
'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
,
)
...
...
@@ -299,10 +298,20 @@ class TestCollectionCachedStorage(TestHashedFiles, CollectionTestCase):
self
.
hashed_file_path
(
'cached/styles.css'
)
@override_settings
(
STATICFILES_STORAGE
=
'staticfiles_tests.storage.ExtraPatternsCachedStaticFilesStorage'
,
)
class
TestExtraPatternsCachedStorage
(
CollectionTestCase
):
class
TestCachedStaticFilesStorageDeprecation
(
SimpleTestCase
):
def
test_warning
(
self
):
from
django.contrib.staticfiles.storage
import
CachedStaticFilesStorage
from
django.utils.deprecation
import
RemovedInDjango31Warning
msg
=
(
'CachedStaticFilesStorage is deprecated in favor of '
'ManifestStaticFilesStorage.'
)
with
self
.
assertRaisesMessage
(
RemovedInDjango31Warning
,
msg
):
CachedStaticFilesStorage
()
@override_settings
(
STATICFILES_STORAGE
=
'staticfiles_tests.storage.ExtraPatternsStorage'
)
class
TestExtraPatternsStorage
(
CollectionTestCase
):
def
setUp
(
self
):
storage
.
staticfiles_storage
.
hashed_files
.
clear
()
# avoid cache interference
...
...
@@ -437,13 +446,8 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase):
self
.
hashed_file_path
(
missing_file_name
)
@override_settings
(
STATICFILES_STORAGE
=
'staticfiles_tests.storage.SimpleCachedStaticFilesStorage'
,
)
class
TestCollectionSimpleCachedStorage
(
CollectionTestCase
):
"""
Tests for the Cache busting storage
"""
@override_settings
(
STATICFILES_STORAGE
=
'staticfiles_tests.storage.SimpleStorage'
)
class
TestCollectionSimpleStorage
(
CollectionTestCase
):
hashed_file_path
=
hashed_file_path
def
setUp
(
self
):
...
...
@@ -451,9 +455,6 @@ class TestCollectionSimpleCachedStorage(CollectionTestCase):
super
()
.
setUp
()
def
test_template_tag_return
(
self
):
"""
Test the CachedStaticFilesStorage backend.
"""
self
.
assertStaticRaises
(
ValueError
,
"does/not/exist.png"
,
"/static/does/not/exist.png"
)
self
.
assertStaticRenders
(
"test/file.txt"
,
"/static/test/file.deploy12345.txt"
)
self
.
assertStaticRenders
(
"cached/styles.css"
,
"/static/cached/styles.deploy12345.css"
)
...
...
@@ -543,7 +544,7 @@ class TestStaticFilePermissions(CollectionTestCase):
@override_settings
(
STATICFILES_STORAGE
=
'django.contrib.staticfiles.storage.
Cached
StaticFilesStorage'
,
STATICFILES_STORAGE
=
'django.contrib.staticfiles.storage.
Manifest
StaticFilesStorage'
,
)
class
TestCollectionHashedFilesCache
(
CollectionTestCase
):
"""
...
...
tests/test_utils/tests.py
Dosyayı görüntüle @
f892781b
...
...
@@ -1092,7 +1092,7 @@ class OverrideSettingsTests(SimpleTestCase):
Overriding the STATICFILES_STORAGE setting should be reflected in
the value of django.contrib.staticfiles.storage.staticfiles_storage.
"""
new_class
=
'
Cached
StaticFilesStorage'
new_class
=
'
Manifest
StaticFilesStorage'
new_storage
=
'django.contrib.staticfiles.storage.'
+
new_class
with
self
.
settings
(
STATICFILES_STORAGE
=
new_storage
):
self
.
assertEqual
(
staticfiles_storage
.
__class__
.
__name__
,
new_class
)
...
...
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