Skip to content

Commit 1d12aa2

Browse files
committed
[1.1.X] Fixed #12879: Declaring the same JS file multiple times in a single Media instance now only includes that file once. Backport of [12663] from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12664 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent c6e662c commit 1d12aa2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

django/forms/widgets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def __getitem__(self, name):
8080

8181
def add_js(self, data):
8282
if data:
83-
self._js.extend([path for path in data if path not in self._js])
83+
for path in data:
84+
if path not in self._js:
85+
self._js.append(path)
8486

8587
def add_css(self, data):
8688
if data:

tests/regressiontests/forms/media.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@
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.
118+
>>> class MyWidget4(TextInput):
119+
... class Media:
120+
... js = ('/path/to/js1', '/path/to/js1')
121+
122+
>>> w4 = MyWidget4()
123+
>>> print w4.media
124+
<script type="text/javascript" src="/path/to/js1"></script>
125+
126+
115127
###############################################################
116128
# Property-based media definitions
117129
###############################################################

0 commit comments

Comments
 (0)