Fixed #10774: accessing form media types in templates (i.e. ``{{ form.media.js }}``) now works. Thanks, tarequeh and Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10489 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
fd443959df
commit
95f5e4a8da
|
@ -75,7 +75,7 @@ class Media(StrAndUnicode):
|
|||
def __getitem__(self, name):
|
||||
"Returns a Media object that only contains media of the given type"
|
||||
if name in MEDIA_TYPES:
|
||||
return Media(**{name: getattr(self, '_' + name)})
|
||||
return Media(**{str(name): getattr(self, '_' + name)})
|
||||
raise KeyError('Unknown media type "%s"' % name)
|
||||
|
||||
def add_js(self, data):
|
||||
|
|
|
@ -355,5 +355,17 @@ media_tests = r"""
|
|||
<script type="text/javascript" src="/path/to/js4"></script>
|
||||
<script type="text/javascript" src="/some/form/javascript"></script>
|
||||
|
||||
# Media works in templates
|
||||
>>> from django.template import Template, Context
|
||||
>>> Template("{{ form.media.js }}{{ form.media.css }}").render(Context({'form': f3}))
|
||||
u'<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="https://secure.other.com/path/to/js3"></script>
|
||||
<script type="text/javascript" src="/path/to/js4"></script>
|
||||
<script type="text/javascript" src="/some/form/javascript"></script><link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
|
||||
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
|
||||
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
|
||||
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />'
|
||||
|
||||
>>> settings.MEDIA_URL = ORIGINAL_MEDIA_URL
|
||||
"""
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue