From e55676e657c466a64ebbdcd122eb0bd2a25ddb0c Mon Sep 17 00:00:00 2001
From: Erik Simmler <tgecho@gmail.com>
Date: Thu, 8 Mar 2012 12:50:48 -0500
Subject: [PATCH] Change CachedFilesMixin url_converter to output relative
paths
---
django/contrib/staticfiles/storage.py | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index fe35a31..93bfe40 100644
a
|
b
|
class CachedFilesMixin(object):
|
165 | 165 | start, end = 1, sub_level - 1 |
166 | 166 | joined_result = '/'.join(name_parts[:-start] + url_parts[end:]) |
167 | 167 | hashed_url = self.url(unquote(joined_result), force=True) |
| 168 | file_name = hashed_url.split('/')[-1:] |
| 169 | relative_url = '/'.join(url.split('/')[:-1] + file_name) |
168 | 170 | |
169 | 171 | # Return the hashed and normalized version to the file |
170 | | return 'url("%s")' % unquote(hashed_url) |
| 172 | return 'url("%s")' % unquote(relative_url) |
171 | 173 | return converter |
172 | 174 | |
173 | 175 | def post_process(self, paths, dry_run=False, **options): |
--
1.7.6
From 6608fbeac561ff4d664ddcf20eead2bf7828568a Mon Sep 17 00:00:00 2001
From: Erik Simmler <tgecho@gmail.com>
Date: Thu, 8 Mar 2012 13:30:02 -0500
Subject: [PATCH] Updated tests to reflect relative url converting
---
tests/regressiontests/staticfiles_tests/tests.py | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
index fc489b3..d09cf6c 100644
a
|
b
|
class TestCollectionCachedStorage(BaseCollectionTestCase,
|
383 | 383 | with storage.staticfiles_storage.open(relpath) as relfile: |
384 | 384 | content = relfile.read() |
385 | 385 | self.assertNotIn("cached/other.css", content) |
386 | | self.assertIn("/static/cached/other.d41d8cd98f00.css", content) |
| 386 | self.assertIn("other.d41d8cd98f00.css", content) |
387 | 387 | |
388 | 388 | def test_path_with_querystring(self): |
389 | 389 | relpath = self.cached_file_path("cached/styles.css?spam=eggs") |
… |
… |
class TestCollectionCachedStorage(BaseCollectionTestCase,
|
393 | 393 | "cached/styles.93b1147e8552.css") as relfile: |
394 | 394 | content = relfile.read() |
395 | 395 | self.assertNotIn("cached/other.css", content) |
396 | | self.assertIn("/static/cached/other.d41d8cd98f00.css", content) |
| 396 | self.assertIn("other.d41d8cd98f00.css", content) |
397 | 397 | |
398 | 398 | def test_path_with_fragment(self): |
399 | 399 | relpath = self.cached_file_path("cached/styles.css#eggs") |
… |
… |
class TestCollectionCachedStorage(BaseCollectionTestCase,
|
402 | 402 | "cached/styles.93b1147e8552.css") as relfile: |
403 | 403 | content = relfile.read() |
404 | 404 | self.assertNotIn("cached/other.css", content) |
405 | | self.assertIn("/static/cached/other.d41d8cd98f00.css", content) |
| 405 | self.assertIn("other.d41d8cd98f00.css", content) |
406 | 406 | |
407 | 407 | def test_path_with_querystring_and_fragment(self): |
408 | 408 | relpath = self.cached_file_path("cached/css/fragments.css") |
409 | 409 | self.assertEqual(relpath, "cached/css/fragments.75433540b096.css") |
410 | 410 | with storage.staticfiles_storage.open(relpath) as relfile: |
411 | 411 | content = relfile.read() |
412 | | self.assertIn('/static/cached/css/fonts/font.a4b0478549d0.eot?#iefix', content) |
413 | | self.assertIn('/static/cached/css/fonts/font.b8d603e42714.svg#webfontIyfZbseF', content) |
| 412 | self.assertIn('fonts/font.a4b0478549d0.eot?#iefix', content) |
| 413 | self.assertIn('fonts/font.b8d603e42714.svg#webfontIyfZbseF', content) |
414 | 414 | self.assertIn('data:font/woff;charset=utf-8;base64,d09GRgABAAAAADJoAA0AAAAAR2QAAQAAAAAAAAAAAAA', content) |
415 | 415 | self.assertIn('#default#VML', content) |
416 | 416 | |
… |
… |
class TestCollectionCachedStorage(BaseCollectionTestCase,
|
429 | 429 | with storage.staticfiles_storage.open(relpath) as relfile: |
430 | 430 | content = relfile.read() |
431 | 431 | self.assertNotIn("..//cached///styles.css", content) |
432 | | self.assertIn("/static/cached/styles.93b1147e8552.css", content) |
| 432 | self.assertIn("../cached/styles.93b1147e8552.css", content) |
433 | 433 | |
434 | 434 | def test_template_tag_relative(self): |
435 | 435 | relpath = self.cached_file_path("cached/relative.css") |
436 | 436 | self.assertEqual(relpath, "cached/relative.2217ea7273c2.css") |
437 | 437 | with storage.staticfiles_storage.open(relpath) as relfile: |
438 | 438 | content = relfile.read() |
439 | | self.assertIn("/static/cached/styles.93b1147e8552.css", content) |
440 | 439 | self.assertNotIn("../cached/styles.css", content) |
441 | 440 | self.assertNotIn('@import "styles.css"', content) |
442 | 441 | self.assertNotIn('url(img/relative.png)', content) |
443 | | self.assertIn('url("/static/cached/img/relative.acae32e4532b.png")', content) |
444 | | self.assertIn("/static/cached/styles.93b1147e8552.css", content) |
| 442 | self.assertIn('url("img/relative.acae32e4532b.png")', content) |
| 443 | self.assertIn("../cached/styles.93b1147e8552.css", content) |
445 | 444 | |
446 | 445 | def test_template_tag_deep_relative(self): |
447 | 446 | relpath = self.cached_file_path("cached/css/window.css") |
… |
… |
class TestCollectionCachedStorage(BaseCollectionTestCase,
|
449 | 448 | with storage.staticfiles_storage.open(relpath) as relfile: |
450 | 449 | content = relfile.read() |
451 | 450 | self.assertNotIn('url(img/window.png)', content) |
452 | | self.assertIn('url("/static/cached/css/img/window.acae32e4532b.png")', content) |
| 451 | self.assertIn('url("img/window.acae32e4532b.png")', content) |
453 | 452 | |
454 | 453 | def test_template_tag_url(self): |
455 | 454 | relpath = self.cached_file_path("cached/url.css") |
--
1.7.6
From 0e9f7849f45d37531dd05223feefc5776557d580 Mon Sep 17 00:00:00 2001
From: Erik Simmler <tgecho@gmail.com>
Date: Thu, 8 Mar 2012 13:30:21 -0500
Subject: [PATCH] Updated comment to reflect new reality
---
django/contrib/staticfiles/storage.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index 93bfe40..dc5f52d 100644
a
|
b
|
class CachedFilesMixin(object):
|
168 | 168 | file_name = hashed_url.split('/')[-1:] |
169 | 169 | relative_url = '/'.join(url.split('/')[:-1] + file_name) |
170 | 170 | |
171 | | # Return the hashed and normalized version to the file |
| 171 | # Return the hashed version to the file |
172 | 172 | return 'url("%s")' % unquote(relative_url) |
173 | 173 | return converter |
174 | 174 | |
--
1.7.6
From c96b3e8a973d2f1e0cc79efef86b08beda8b90c9 Mon Sep 17 00:00:00 2001
From: Erik Simmler <tgecho@gmail.com>
Date: Thu, 8 Mar 2012 13:30:29 -0500
Subject: [PATCH] Updated docs to reflect relative url converting
---
docs/ref/contrib/staticfiles.txt | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/docs/ref/contrib/staticfiles.txt b/docs/ref/contrib/staticfiles.txt
index 368154c..1dbd00b 100644
a
|
b
|
CachedStaticFilesStorage
|
327 | 327 | |
328 | 328 | .. code-block:: css+django |
329 | 329 | |
330 | | @import url("/static/admin/css/base.27e20196a850.css"); |
| 330 | @import url("../admin/css/base.27e20196a850.css"); |
331 | 331 | |
332 | 332 | To enable the ``CachedStaticFilesStorage`` you have to make sure the |
333 | 333 | following requirements are met: |