0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

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:
Jacob Kaplan-Moss 2009-04-10 17:07:25 +00:00
parent fd443959df
commit 95f5e4a8da
2 changed files with 14 additions and 2 deletions

View File

@ -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):

View File

@ -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
"""