Code

Ticket #17857: patch.diff

File patch.diff, 7.5 KB (added by tgecho, 2 years ago)
Line 
1From e55676e657c466a64ebbdcd122eb0bd2a25ddb0c Mon Sep 17 00:00:00 2001
2From: Erik Simmler <tgecho@gmail.com>
3Date: Thu, 8 Mar 2012 12:50:48 -0500
4Subject: [PATCH] Change CachedFilesMixin url_converter to output relative
5 paths
6
7---
8 django/contrib/staticfiles/storage.py |    4 +++-
9 1 files changed, 3 insertions(+), 1 deletions(-)
10
11diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
12index fe35a31..93bfe40 100644
13--- a/django/contrib/staticfiles/storage.py
14+++ b/django/contrib/staticfiles/storage.py
15@@ -165,9 +165,11 @@ class CachedFilesMixin(object):
16                     start, end = 1, sub_level - 1
17             joined_result = '/'.join(name_parts[:-start] + url_parts[end:])
18             hashed_url = self.url(unquote(joined_result), force=True)
19+            file_name = hashed_url.split('/')[-1:]
20+            relative_url = '/'.join(url.split('/')[:-1] + file_name)
21 
22             # Return the hashed and normalized version to the file
23-            return 'url("%s")' % unquote(hashed_url)
24+            return 'url("%s")' % unquote(relative_url)
25         return converter
26 
27     def post_process(self, paths, dry_run=False, **options):
28--
291.7.6
30
31From 6608fbeac561ff4d664ddcf20eead2bf7828568a Mon Sep 17 00:00:00 2001
32From: Erik Simmler <tgecho@gmail.com>
33Date: Thu, 8 Mar 2012 13:30:02 -0500
34Subject: [PATCH] Updated tests to reflect relative url converting
35
36---
37 tests/regressiontests/staticfiles_tests/tests.py |   19 +++++++++----------
38 1 files changed, 9 insertions(+), 10 deletions(-)
39
40diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
41index fc489b3..d09cf6c 100644
42--- a/tests/regressiontests/staticfiles_tests/tests.py
43+++ b/tests/regressiontests/staticfiles_tests/tests.py
44@@ -383,7 +383,7 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
45         with storage.staticfiles_storage.open(relpath) as relfile:
46             content = relfile.read()
47             self.assertNotIn("cached/other.css", content)
48-            self.assertIn("/static/cached/other.d41d8cd98f00.css", content)
49+            self.assertIn("other.d41d8cd98f00.css", content)
50 
51     def test_path_with_querystring(self):
52         relpath = self.cached_file_path("cached/styles.css?spam=eggs")
53@@ -393,7 +393,7 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
54                 "cached/styles.93b1147e8552.css") as relfile:
55             content = relfile.read()
56             self.assertNotIn("cached/other.css", content)
57-            self.assertIn("/static/cached/other.d41d8cd98f00.css", content)
58+            self.assertIn("other.d41d8cd98f00.css", content)
59 
60     def test_path_with_fragment(self):
61         relpath = self.cached_file_path("cached/styles.css#eggs")
62@@ -402,15 +402,15 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
63                 "cached/styles.93b1147e8552.css") as relfile:
64             content = relfile.read()
65             self.assertNotIn("cached/other.css", content)
66-            self.assertIn("/static/cached/other.d41d8cd98f00.css", content)
67+            self.assertIn("other.d41d8cd98f00.css", content)
68 
69     def test_path_with_querystring_and_fragment(self):
70         relpath = self.cached_file_path("cached/css/fragments.css")
71         self.assertEqual(relpath, "cached/css/fragments.75433540b096.css")
72         with storage.staticfiles_storage.open(relpath) as relfile:
73             content = relfile.read()
74-            self.assertIn('/static/cached/css/fonts/font.a4b0478549d0.eot?#iefix', content)
75-            self.assertIn('/static/cached/css/fonts/font.b8d603e42714.svg#webfontIyfZbseF', content)
76+            self.assertIn('fonts/font.a4b0478549d0.eot?#iefix', content)
77+            self.assertIn('fonts/font.b8d603e42714.svg#webfontIyfZbseF', content)
78             self.assertIn('data:font/woff;charset=utf-8;base64,d09GRgABAAAAADJoAA0AAAAAR2QAAQAAAAAAAAAAAAA', content)
79             self.assertIn('#default#VML', content)
80 
81@@ -429,19 +429,18 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
82         with storage.staticfiles_storage.open(relpath) as relfile:
83             content = relfile.read()
84             self.assertNotIn("..//cached///styles.css", content)
85-            self.assertIn("/static/cached/styles.93b1147e8552.css", content)
86+            self.assertIn("../cached/styles.93b1147e8552.css", content)
87 
88     def test_template_tag_relative(self):
89         relpath = self.cached_file_path("cached/relative.css")
90         self.assertEqual(relpath, "cached/relative.2217ea7273c2.css")
91         with storage.staticfiles_storage.open(relpath) as relfile:
92             content = relfile.read()
93-            self.assertIn("/static/cached/styles.93b1147e8552.css", content)
94             self.assertNotIn("../cached/styles.css", content)
95             self.assertNotIn('@import "styles.css"', content)
96             self.assertNotIn('url(img/relative.png)', content)
97-            self.assertIn('url("/static/cached/img/relative.acae32e4532b.png")', content)
98-            self.assertIn("/static/cached/styles.93b1147e8552.css", content)
99+            self.assertIn('url("img/relative.acae32e4532b.png")', content)
100+            self.assertIn("../cached/styles.93b1147e8552.css", content)
101 
102     def test_template_tag_deep_relative(self):
103         relpath = self.cached_file_path("cached/css/window.css")
104@@ -449,7 +448,7 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
105         with storage.staticfiles_storage.open(relpath) as relfile:
106             content = relfile.read()
107             self.assertNotIn('url(img/window.png)', content)
108-            self.assertIn('url("/static/cached/css/img/window.acae32e4532b.png")', content)
109+            self.assertIn('url("img/window.acae32e4532b.png")', content)
110 
111     def test_template_tag_url(self):
112         relpath = self.cached_file_path("cached/url.css")
113--
1141.7.6
115
116From 0e9f7849f45d37531dd05223feefc5776557d580 Mon Sep 17 00:00:00 2001
117From: Erik Simmler <tgecho@gmail.com>
118Date: Thu, 8 Mar 2012 13:30:21 -0500
119Subject: [PATCH] Updated comment to reflect new reality
120
121---
122 django/contrib/staticfiles/storage.py |    2 +-
123 1 files changed, 1 insertions(+), 1 deletions(-)
124
125diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
126index 93bfe40..dc5f52d 100644
127--- a/django/contrib/staticfiles/storage.py
128+++ b/django/contrib/staticfiles/storage.py
129@@ -168,7 +168,7 @@ class CachedFilesMixin(object):
130             file_name = hashed_url.split('/')[-1:]
131             relative_url = '/'.join(url.split('/')[:-1] + file_name)
132 
133-            # Return the hashed and normalized version to the file
134+            # Return the hashed version to the file
135             return 'url("%s")' % unquote(relative_url)
136         return converter
137 
138--
1391.7.6
140
141From c96b3e8a973d2f1e0cc79efef86b08beda8b90c9 Mon Sep 17 00:00:00 2001
142From: Erik Simmler <tgecho@gmail.com>
143Date: Thu, 8 Mar 2012 13:30:29 -0500
144Subject: [PATCH] Updated docs to reflect relative url converting
145
146---
147 docs/ref/contrib/staticfiles.txt |    2 +-
148 1 files changed, 1 insertions(+), 1 deletions(-)
149
150diff --git a/docs/ref/contrib/staticfiles.txt b/docs/ref/contrib/staticfiles.txt
151index 368154c..1dbd00b 100644
152--- a/docs/ref/contrib/staticfiles.txt
153+++ b/docs/ref/contrib/staticfiles.txt
154@@ -327,7 +327,7 @@ CachedStaticFilesStorage
155 
156     .. code-block:: css+django
157 
158-        @import url("/static/admin/css/base.27e20196a850.css");
159+        @import url("../admin/css/base.27e20196a850.css");
160 
161     To enable the ``CachedStaticFilesStorage`` you have to make sure the
162     following requirements are met:
163--
1641.7.6
165