Skip to content

Commit 6edcd11

Browse files
committed
Expanded the fix in [12663] to cover CSS declarations, which were also affected by the bug. Refs #12879.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12665 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 9a82ca0 commit 6edcd11

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

django/forms/widgets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def add_js(self, data):
8282
def add_css(self, data):
8383
if data:
8484
for medium, paths in data.items():
85-
self._css.setdefault(medium, []).extend([path for path in paths if path not in self._css[medium]])
85+
for path in paths:
86+
if not self._css.get(medium) or path not in self._css[medium]:
87+
self._css.setdefault(medium, []).append(path)
8688

8789
def __add__(self, other):
8890
combined = Media()

tests/regressiontests/forms/media.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,17 @@
112112
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
113113
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
114114
115-
# Regression check for #12879: specifying the same JS file multiple
116-
# times in a single Media instance should result in that file only
117-
# being included once.
115+
# Regression check for #12879: specifying the same CSS or JS file
116+
# multiple times in a single Media instance should result in that file
117+
# only being included once.
118118
>>> class MyWidget4(TextInput):
119119
... class Media:
120+
... css = {'all': ('/path/to/css1', '/path/to/css1')}
120121
... js = ('/path/to/js1', '/path/to/js1')
121122
122123
>>> w4 = MyWidget4()
123124
>>> print w4.media
125+
<link href="/path/to/css1" type="text/css" media="all" rel="stylesheet" />
124126
<script type="text/javascript" src="/path/to/js1"></script>
125127
126128

0 commit comments

Comments
 (0)