Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 95f5e4a8daceb351b8e12b52489d37f1408b140b 1 parent fd44395
Jacob Kaplan-Moss jacobian authored
Showing with 14 additions and 2 deletions.
  1. +1 −1  django/forms/widgets.py
  2. +13 −1 tests/regressiontests/forms/media.py
2  django/forms/widgets.py
View
@@ -75,7 +75,7 @@ def absolute_path(self, path):
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):
14 tests/regressiontests/forms/media.py
View
@@ -355,5 +355,17 @@
<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
-"""
+"""
Please sign in to comment.
Something went wrong with that request. Please try again.