Code

Ticket #12879: 12879.diff

File 12879.diff, 1.4 KB (added by ubernostrum, 4 years ago)

Patch + test case

Line 
1Index: django/forms/widgets.py
2===================================================================
3--- django/forms/widgets.py     (revision 12662)
4+++ django/forms/widgets.py     (working copy)
5@@ -75,7 +75,9 @@
6 
7     def add_js(self, data):
8         if data:
9-            self._js.extend([path for path in data if path not in self._js])
10+            for path in data:
11+                if path not in self._js:
12+                    self._js.append(path)
13 
14     def add_css(self, data):
15         if data:
16Index: tests/regressiontests/forms/media.py
17===================================================================
18--- tests/regressiontests/forms/media.py        (revision 12662)
19+++ tests/regressiontests/forms/media.py        (working copy)
20@@ -112,6 +112,18 @@
21 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
22 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
23 
24+# Regression check for #12879: specifying the same JS file multiple
25+# times in a single Media instance should result in that file only
26+# being included once.
27+>>> class MyWidget4(TextInput):
28+...     class Media:
29+...         js = ('/path/to/js1', '/path/to/js1')
30+
31+>>> w4 = MyWidget4()
32+>>> print w4.media
33+<script type="text/javascript" src="/path/to/js1"></script>
34+
35+
36 ###############################################################
37 # Property-based media definitions
38 ###############################################################