mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #19670 -- Applied CachedFilesMixin patterns to specific extensions
Thanks Simon Meers for the initial patch, and Tim Graham for the review.
This commit is contained in:
@@ -17,6 +17,7 @@ from django.core.files.base import ContentFile
|
||||
from django.core.files.storage import FileSystemStorage, get_storage_class
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.functional import LazyObject
|
||||
from django.utils.six import iteritems
|
||||
from django.utils.six.moves.urllib.parse import (
|
||||
unquote, urldefrag, urlsplit, urlunsplit,
|
||||
)
|
||||
@@ -248,13 +249,14 @@ class HashedFilesMixin(object):
|
||||
# ..to apply each replacement pattern to the content
|
||||
if name in adjustable_paths:
|
||||
content = original_file.read().decode(settings.FILE_CHARSET)
|
||||
for patterns in self._patterns.values():
|
||||
for pattern, template in patterns:
|
||||
converter = self.url_converter(name, template)
|
||||
try:
|
||||
content = pattern.sub(converter, content)
|
||||
except ValueError as exc:
|
||||
yield name, None, exc
|
||||
for extension, patterns in iteritems(self._patterns):
|
||||
if matches_patterns(path, (extension,)):
|
||||
for pattern, template in patterns:
|
||||
converter = self.url_converter(name, template)
|
||||
try:
|
||||
content = pattern.sub(converter, content)
|
||||
except ValueError as exc:
|
||||
yield name, None, exc
|
||||
if hashed_file_exists:
|
||||
self.delete(hashed_name)
|
||||
# then save the processed result
|
||||
|
||||
Reference in New Issue
Block a user