Commit 1d12aa2c authored by James Bennett's avatar James Bennett
Browse files

[1.1.X] Fixed #12879: Declaring the same JS file multiple times in a single...

[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
parent c6e662cd
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -80,7 +80,9 @@ class Media(StrAndUnicode):

    def add_js(self, 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):
        if data:
+12 −0
Original line number Diff line number Diff line
@@ -112,6 +112,18 @@ media_tests = r"""
<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.
>>> 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
###############################################################