1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

Fixed #5211 -- Added paths starting with '/' to the list of paths that are preserved as-is by the widget media framework.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5986 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2007-08-20 13:24:10 +00:00
parent c49f2d21ea
commit 88987ed0ac
3 changed files with 106 additions and 99 deletions

View File

@ -14,6 +14,7 @@ from django.utils.html import escape
from django.utils.translation import ugettext from django.utils.translation import ugettext
from django.utils.encoding import StrAndUnicode, force_unicode from django.utils.encoding import StrAndUnicode, force_unicode
from util import flatatt from util import flatatt
from urlparse import urljoin
__all__ = ( __all__ = (
'Media', 'Widget', 'TextInput', 'PasswordInput', 'Media', 'Widget', 'TextInput', 'PasswordInput',
@ -62,7 +63,9 @@ class Media(StrAndUnicode):
for medium in media]) for medium in media])
def absolute_path(self, path): def absolute_path(self, path):
return (path.startswith(u'http://') or path.startswith(u'https://')) and path or u''.join([settings.MEDIA_URL,path]) if path.startswith(u'http://') or path.startswith(u'https://') or path.startswith(u'/'):
return path
return urljoin(settings.MEDIA_URL,path)
def __getitem__(self, name): def __getitem__(self, name):
"Returns a Media object that only contains media of the given type" "Returns a Media object that only contains media of the given type"

View File

@ -2139,17 +2139,21 @@ Paths in media definitions
-------------------------- --------------------------
Paths used to specify media can be either relative or absolute. If a path Paths used to specify media can be either relative or absolute. If a path
starts with 'http://' or 'https://', it will be interpreted as an absolute starts with '/', 'http://' or 'https://', it will be interpreted as an absolute
path, and left as-is. All other paths will be prepended with the value of path, and left as-is. All other paths will be prepended with the value of
``settings.MEDIA_URL``. For example, if the MEDIA_URL for your site was ``settings.MEDIA_URL``. For example, if the MEDIA_URL for your site was
``http://media.example.com/``:: ``http://media.example.com/``::
class CalendarWidget(forms.TextInput): class CalendarWidget(forms.TextInput):
class Media: class Media:
css = {
'all': ('/css/pretty.css',),
}
js = ('animations.js', 'http://othersite.com/actions.js') js = ('animations.js', 'http://othersite.com/actions.js')
>>> w = CalendarWidget() >>> w = CalendarWidget()
>>> print w.media >>> print w.media
<link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/animations.js"></script> <script type="text/javascript" src="http://media.example.com/animations.js"></script>
<script type="text/javascript" src="http://othersite.com/actions.js"></script> <script type="text/javascript" src="http://othersite.com/actions.js"></script>

View File

@ -4,35 +4,35 @@
media_tests = r""" media_tests = r"""
>>> from django.newforms import TextInput, Media, TextInput, CharField, Form, MultiWidget >>> from django.newforms import TextInput, Media, TextInput, CharField, Form, MultiWidget
>>> from django.conf import settings >>> from django.conf import settings
>>> settings.MEDIA_URL = 'http://media.example.com' >>> settings.MEDIA_URL = 'http://media.example.com/media/'
# Check construction of media objects # Check construction of media objects
>>> m = Media(css={'all': ('/path/to/css1','/path/to/css2')}, js=('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')) >>> m = Media(css={'all': ('path/to/css1','/path/to/css2')}, js=('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3'))
>>> print m >>> print m
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
>>> class Foo: >>> class Foo:
... css = { ... css = {
... 'all': ('/path/to/css1','/path/to/css2') ... 'all': ('path/to/css1','/path/to/css2')
... } ... }
... js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3') ... js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
>>> m3 = Media(Foo) >>> m3 = Media(Foo)
>>> print m3 >>> print m3
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
>>> m3 = Media(Foo) >>> m3 = Media(Foo)
>>> print m3 >>> print m3
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
@ -54,25 +54,25 @@ media_tests = r"""
>>> class MyWidget1(TextInput): >>> class MyWidget1(TextInput):
... class Media: ... class Media:
... css = { ... css = {
... 'all': ('/path/to/css1','/path/to/css2') ... 'all': ('path/to/css1','/path/to/css2')
... } ... }
... js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3') ... js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
>>> w1 = MyWidget1() >>> w1 = MyWidget1()
>>> print w1.media >>> print w1.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
# Media objects can be interrogated by media type # Media objects can be interrogated by media type
>>> print w1.media['css'] >>> print w1.media['css']
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
>>> print w1.media['js'] >>> print w1.media['js']
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
@ -88,26 +88,26 @@ media_tests = r"""
>>> class MyWidget3(TextInput): >>> class MyWidget3(TextInput):
... class Media: ... class Media:
... css = { ... css = {
... 'all': ('/path/to/css3','/path/to/css1') ... 'all': ('/path/to/css3','path/to/css1')
... } ... }
... js = ('/path/to/js1','/path/to/js4') ... js = ('/path/to/js1','/path/to/js4')
>>> w2 = MyWidget2() >>> w2 = MyWidget2()
>>> w3 = MyWidget3() >>> w3 = MyWidget3()
>>> print w1.media + w2.media + w3.media >>> print w1.media + w2.media + w3.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
# Check that media addition hasn't affected the original objects # Check that media addition hasn't affected the original objects
>>> print w1.media >>> print w1.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
@ -123,8 +123,8 @@ media_tests = r"""
>>> w4 = MyWidget4() >>> w4 = MyWidget4()
>>> print w4.media >>> print w4.media
<link href="http://media.example.com/some/path" type="text/css" media="all" rel="stylesheet" /> <link href="/some/path" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/some/js"></script> <script type="text/javascript" src="/some/js"></script>
# Media properties can reference the media of their parents # Media properties can reference the media of their parents
>>> class MyWidget5(MyWidget4): >>> class MyWidget5(MyWidget4):
@ -134,10 +134,10 @@ media_tests = r"""
>>> w5 = MyWidget5() >>> w5 = MyWidget5()
>>> print w5.media >>> print w5.media
<link href="http://media.example.com/some/path" type="text/css" media="all" rel="stylesheet" /> <link href="/some/path" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/other/path" type="text/css" media="all" rel="stylesheet" /> <link href="/other/path" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/some/js"></script> <script type="text/javascript" src="/some/js"></script>
<script type="text/javascript" src="http://media.example.com/other/js"></script> <script type="text/javascript" src="/other/js"></script>
# Media properties can reference the media of their parents, # Media properties can reference the media of their parents,
# even if the parent media was defined using a class # even if the parent media was defined using a class
@ -148,13 +148,13 @@ media_tests = r"""
>>> w6 = MyWidget6() >>> w6 = MyWidget6()
>>> print w6.media >>> print w6.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/other/path" type="text/css" media="all" rel="stylesheet" /> <link href="/other/path" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
<script type="text/javascript" src="http://media.example.com/other/js"></script> <script type="text/javascript" src="/other/js"></script>
############################################################### ###############################################################
# Inheritance of media # Inheritance of media
@ -166,9 +166,9 @@ media_tests = r"""
>>> w7 = MyWidget7() >>> w7 = MyWidget7()
>>> print w7.media >>> print w7.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
@ -176,19 +176,19 @@ media_tests = r"""
>>> class MyWidget8(MyWidget1): >>> class MyWidget8(MyWidget1):
... class Media: ... class Media:
... css = { ... css = {
... 'all': ('/path/to/css3','/path/to/css1') ... 'all': ('/path/to/css3','path/to/css1')
... } ... }
... js = ('/path/to/js1','/path/to/js4') ... js = ('/path/to/js1','/path/to/js4')
>>> w8 = MyWidget8() >>> w8 = MyWidget8()
>>> print w8.media >>> print w8.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
# If a widget extends another but defines media, it extends the parents widget's media, # If a widget extends another but defines media, it extends the parents widget's media,
# even if the parent defined media using a property. # even if the parent defined media using a property.
@ -201,62 +201,62 @@ media_tests = r"""
>>> w9 = MyWidget9() >>> w9 = MyWidget9()
>>> print w9.media >>> print w9.media
<link href="http://media.example.com/some/path" type="text/css" media="all" rel="stylesheet" /> <link href="/some/path" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/other/path" type="text/css" media="all" rel="stylesheet" /> <link href="/other/path" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/some/js"></script> <script type="text/javascript" src="/some/js"></script>
<script type="text/javascript" src="http://media.example.com/other/js"></script> <script type="text/javascript" src="/other/js"></script>
# A widget can disable media inheritance by specifying 'extend=False' # A widget can disable media inheritance by specifying 'extend=False'
>>> class MyWidget10(MyWidget1): >>> class MyWidget10(MyWidget1):
... class Media: ... class Media:
... extend = False ... extend = False
... css = { ... css = {
... 'all': ('/path/to/css3','/path/to/css1') ... 'all': ('/path/to/css3','path/to/css1')
... } ... }
... js = ('/path/to/js1','/path/to/js4') ... js = ('/path/to/js1','/path/to/js4')
>>> w10 = MyWidget10() >>> w10 = MyWidget10()
>>> print w10.media >>> print w10.media
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
# A widget can explicitly enable full media inheritance by specifying 'extend=True' # A widget can explicitly enable full media inheritance by specifying 'extend=True'
>>> class MyWidget11(MyWidget1): >>> class MyWidget11(MyWidget1):
... class Media: ... class Media:
... extend = True ... extend = True
... css = { ... css = {
... 'all': ('/path/to/css3','/path/to/css1') ... 'all': ('/path/to/css3','path/to/css1')
... } ... }
... js = ('/path/to/js1','/path/to/js4') ... js = ('/path/to/js1','/path/to/js4')
>>> w11 = MyWidget11() >>> w11 = MyWidget11()
>>> print w11.media >>> print w11.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
# A widget can enable inheritance of one media type by specifying extend as a tuple # A widget can enable inheritance of one media type by specifying extend as a tuple
>>> class MyWidget12(MyWidget1): >>> class MyWidget12(MyWidget1):
... class Media: ... class Media:
... extend = ('css',) ... extend = ('css',)
... css = { ... css = {
... 'all': ('/path/to/css3','/path/to/css1') ... 'all': ('/path/to/css3','path/to/css1')
... } ... }
... js = ('/path/to/js1','/path/to/js4') ... js = ('/path/to/js1','/path/to/js4')
>>> w12 = MyWidget12() >>> w12 = MyWidget12()
>>> print w12.media >>> print w12.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
############################################################### ###############################################################
# Multi-media handling for CSS # Multi-media handling for CSS
@ -274,12 +274,12 @@ media_tests = r"""
>>> multimedia = MultimediaWidget() >>> multimedia = MultimediaWidget()
>>> print multimedia.media >>> print multimedia.media
<link href="http://media.example.com/file4" type="text/css" media="print" rel="stylesheet" /> <link href="/file4" type="text/css" media="print" rel="stylesheet" />
<link href="http://media.example.com/file3" type="text/css" media="screen" rel="stylesheet" /> <link href="/file3" type="text/css" media="screen" rel="stylesheet" />
<link href="http://media.example.com/file1" type="text/css" media="screen, print" rel="stylesheet" /> <link href="/file1" type="text/css" media="screen, print" rel="stylesheet" />
<link href="http://media.example.com/file2" type="text/css" media="screen, print" rel="stylesheet" /> <link href="/file2" type="text/css" media="screen, print" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
############################################################### ###############################################################
# Multiwidget media handling # Multiwidget media handling
@ -294,13 +294,13 @@ media_tests = r"""
>>> mymulti = MyMultiWidget() >>> mymulti = MyMultiWidget()
>>> print mymulti.media >>> print mymulti.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
############################################################### ###############################################################
# Media processing for forms # Media processing for forms
@ -312,26 +312,26 @@ media_tests = r"""
... field2 = CharField(max_length=20, widget=MyWidget2()) ... field2 = CharField(max_length=20, widget=MyWidget2())
>>> f1 = MyForm() >>> f1 = MyForm()
>>> print f1.media >>> print f1.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
# Form media can be combined to produce a single media definition. # Form media can be combined to produce a single media definition.
>>> class AnotherForm(Form): >>> class AnotherForm(Form):
... field3 = CharField(max_length=20, widget=MyWidget3()) ... field3 = CharField(max_length=20, widget=MyWidget3())
>>> f2 = AnotherForm() >>> f2 = AnotherForm()
>>> print f1.media + f2.media >>> print f1.media + f2.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
# Forms can also define media, following the same rules as widgets. # Forms can also define media, following the same rules as widgets.
>>> class FormWithMedia(Form): >>> class FormWithMedia(Form):
@ -344,14 +344,14 @@ media_tests = r"""
... } ... }
>>> f3 = FormWithMedia() >>> f3 = FormWithMedia()
>>> print f3.media >>> print f3.media
<link href="http://media.example.com/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/some/form/css" type="text/css" media="all" rel="stylesheet" /> <link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<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>
<script type="text/javascript" src="http://media.example.com/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
<script type="text/javascript" src="http://media.example.com/some/form/javascript"></script> <script type="text/javascript" src="/some/form/javascript"></script>
""" """