Navigation Menu

Skip to content

Commit

Permalink
Fixed #12879: Declaring the same JS file multiple times in a single M…
Browse files Browse the repository at this point in the history
…edia instance now only includes that file once.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12663 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
ubernostrum committed Mar 3, 2010
1 parent 600aa66 commit 9a82ca0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion django/forms/widgets.py
Expand Up @@ -75,7 +75,9 @@ def __getitem__(self, name):


def add_js(self, data): def add_js(self, data):
if data: if data:
self._js.extend([path for path in data if path not in self._js]) for path in data:
if path not in self._js:
self._js.append(path)


def add_css(self, data): def add_css(self, data):
if data: if data:
Expand Down
12 changes: 12 additions & 0 deletions tests/regressiontests/forms/media.py
Expand Up @@ -112,6 +112,18 @@
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
# Regression check for #12879: specifying the same JS file multiple
# times in a single Media instance should result in that file only
# being included once.
>>> class MyWidget4(TextInput):
... class Media:
... js = ('/path/to/js1', '/path/to/js1')
>>> w4 = MyWidget4()
>>> print w4.media
<script type="text/javascript" src="/path/to/js1"></script>
############################################################### ###############################################################
# Property-based media definitions # Property-based media definitions
############################################################### ###############################################################
Expand Down

0 comments on commit 9a82ca0

Please sign in to comment.