Skip to content

Commit

Permalink
[1.1.X] Expanded the fix in [12663] to cover CSS declarations, which …
Browse files Browse the repository at this point in the history
…were also affected by the bug. Refs #12879. Backport of [12665] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12666 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
ubernostrum committed Mar 3, 2010
1 parent 1d12aa2 commit faa341e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion django/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def add_js(self, data):
def add_css(self, data):
if data:
for medium, paths in data.items():
self._css.setdefault(medium, []).extend([path for path in paths if path not in self._css[medium]])
for path in paths:
if not self._css.get(medium) or path not in self._css[medium]:
self._css.setdefault(medium, []).append(path)

def __add__(self, other):
combined = Media()
Expand Down
8 changes: 5 additions & 3 deletions tests/regressiontests/forms/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,17 @@
<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>
# 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.
# Regression check for #12879: specifying the same CSS or JS file
# multiple times in a single Media instance should result in that file
# only being included once.
>>> class MyWidget4(TextInput):
... class Media:
... css = {'all': ('/path/to/css1', '/path/to/css1')}
... js = ('/path/to/js1', '/path/to/js1')
>>> w4 = MyWidget4()
>>> print w4.media
<link href="/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
Expand Down

0 comments on commit faa341e

Please sign in to comment.