Skip to content

Commit

Permalink
Fixed #17689 -- Stopped the CachedStaticFilesStorage from trying to h…
Browse files Browse the repository at this point in the history
…ash paths that aren't files.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17535 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jezdez committed Feb 16, 2012
1 parent 8f4d12e commit 758a0cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 10 additions & 7 deletions django/contrib/staticfiles/storage.py
Expand Up @@ -105,13 +105,16 @@ def url(self, name, force=False):
hashed_name, fragment = name, '' hashed_name, fragment = name, ''
else: else:
clean_name, fragment = urldefrag(name) clean_name, fragment = urldefrag(name)
cache_key = self.cache_key(name) if urlsplit(clean_name).path.endswith('/'): # don't hash paths
hashed_name = self.cache.get(cache_key) hashed_name = name
if hashed_name is None: else:
hashed_name = self.hashed_name(clean_name).replace('\\', '/') cache_key = self.cache_key(name)
# set the cache if there was a miss hashed_name = self.cache.get(cache_key)
# (e.g. if cache server goes down) if hashed_name is None:
self.cache.set(cache_key, hashed_name) hashed_name = self.hashed_name(clean_name).replace('\\', '/')
# set the cache if there was a miss
# (e.g. if cache server goes down)
self.cache.set(cache_key, hashed_name)


final_url = super(CachedFilesMixin, self).url(hashed_name) final_url = super(CachedFilesMixin, self).url(hashed_name)


Expand Down
4 changes: 4 additions & 0 deletions tests/regressiontests/staticfiles_tests/tests.py
Expand Up @@ -317,6 +317,10 @@ def test_template_tag_return(self):
"/static/test/file.ea5bccaf16d5.txt") "/static/test/file.ea5bccaf16d5.txt")
self.assertStaticRenders("cached/styles.css", self.assertStaticRenders("cached/styles.css",
"/static/cached/styles.93b1147e8552.css") "/static/cached/styles.93b1147e8552.css")
self.assertStaticRenders("path/",
"/static/path/")
self.assertStaticRenders("path/?query",
"/static/path/?query")


def test_template_tag_simple_content(self): def test_template_tag_simple_content(self):
relpath = self.cached_file_path("cached/styles.css") relpath = self.cached_file_path("cached/styles.css")
Expand Down

0 comments on commit 758a0cd

Please sign in to comment.