Browse files

Merge branch 'release/1.2.1'

  • Loading branch information...
2 parents b449a80 + 2429b1f commit cd4e024e44c0be909333fcac5c328b2e4d2747bd @jezdez jezdez committed Feb 16, 2012
View
7 docs/changelog.rst
@@ -1,6 +1,13 @@
Changelog
=========
+v1.2.1 (2012-02-16)
+-------------------
+
+* Backported a change from Django trunk that prevents openening too
+ many files at once when running the ``collectstatic`` management
+ command.
+
v1.2 (2012-02-12)
-----------------
View
2 staticfiles/__init__.py
@@ -1,2 +1,2 @@
# following PEP 386
-__version__ = "1.2"
+__version__ = "1.2.1"
View
3 staticfiles/management/commands/collectstatic.py
@@ -45,6 +45,7 @@ class Command(NoArgsCommand):
"'.*' and '*~'."),
)
help = "Collect static files in a single location."
+ requires_model_validation = False
def __init__(self, *args, **kwargs):
super(NoArgsCommand, self).__init__(*args, **kwargs)
@@ -108,7 +109,7 @@ def collect(self):
prefixed_path = os.path.join(storage.prefix, path)
else:
prefixed_path = path
- found_files[prefixed_path] = storage.open(path)
+ found_files[prefixed_path] = (storage, path)
handler(path, prefixed_path, storage)
# Here we check if the storage backend has a post_process
View
9 staticfiles/storage.py
@@ -41,8 +41,6 @@ def __exit__(self, exc_type, exc_value, tb):
setattr_ifmissing([File, ContentFile], '__enter__', __enter__)
setattr_ifmissing([File, ContentFile], '__exit__', __exit__)
-fragments_re = re.compile(r'([?#].*)$')
-
class TimeAwareFileSystemStorage(FileSystemStorage):
def accessed_time(self, name):
@@ -139,6 +137,10 @@ def hashed_name(self, name, content=None):
(root, md5sum, ext))
unparsed_name = list(parsed_name)
unparsed_name[2] = hashed_name
+ # Special casing for a @font-face hack, like url(myfont.eot?#iefix")
+ # http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax
+ if '?#' in name and not unparsed_name[3]:
+ unparsed_name[2] += '?'
return urlunsplit(unparsed_name)
def cache_key(self, name):
@@ -245,7 +247,8 @@ def post_process(self, paths, dry_run=False, **options):
# use the original, local file, not the copied-but-unprocessed
# file, which might be somewhere far away, like S3
- with paths[name] as original_file:
+ storage, path = paths[name]
+ with storage.open(path) as original_file:
# generate the hash with the original content, even for
# adjustable files.
View
15 staticfiles/tests/tests.py
@@ -444,6 +444,21 @@ def test_template_tag_url(self):
with storage.staticfiles_storage.open(relpath) as relfile:
self.assertIn("https://", relfile.read())
+ def test_cache_invalidation(self):
+ name = "cached/styles.css"
+ hashed_name = "cached/styles.93b1147e8552.css"
+ # check if the cache is filled correctly as expected
+ cache_key = storage.staticfiles_storage.cache_key(name)
+ cached_name = storage.staticfiles_storage.cache.get(cache_key)
+ self.assertEqual(self.cached_file_path(name), cached_name)
+ # clearing the cache to make sure we re-set it correctly in the url method
+ storage.staticfiles_storage.cache.clear()
+ cached_name = storage.staticfiles_storage.cache.get(cache_key)
+ self.assertEqual(cached_name, None)
+ self.assertEqual(self.cached_file_path(name), hashed_name)
+ cached_name = storage.staticfiles_storage.cache.get(cache_key)
+ self.assertEqual(cached_name, hashed_name)
+
def test_post_processing(self):
"""Test that post_processing behaves correctly.

0 comments on commit cd4e024

Please sign in to comment.