Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored April 10, 2009
2  django/forms/widgets.py
@@ -75,7 +75,7 @@ def absolute_path(self, path):
75 75
     def __getitem__(self, name):
76 76
         "Returns a Media object that only contains media of the given type"
77 77
         if name in MEDIA_TYPES:
78  
-            return Media(**{name: getattr(self, '_' + name)})
  78
+            return Media(**{str(name): getattr(self, '_' + name)})
79 79
         raise KeyError('Unknown media type "%s"' % name)
80 80
 
81 81
     def add_js(self, data):
14  tests/regressiontests/forms/media.py
@@ -355,5 +355,17 @@
355 355
 <script type="text/javascript" src="/path/to/js4"></script>
356 356
 <script type="text/javascript" src="/some/form/javascript"></script>
357 357
 
  358
+# Media works in templates
  359
+>>> from django.template import Template, Context
  360
+>>> Template("{{ form.media.js }}{{ form.media.css }}").render(Context({'form': f3}))
  361
+u'<script type="text/javascript" src="/path/to/js1"></script>
  362
+<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
  363
+<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
  364
+<script type="text/javascript" src="/path/to/js4"></script>
  365
+<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" />
  366
+<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
  367
+<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
  368
+<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />'
  369
+
358 370
 >>> settings.MEDIA_URL = ORIGINAL_MEDIA_URL
359  
-"""
  371
+"""

0 notes on commit 95f5e4a

Please sign in to comment.
Something went wrong with that request. Please try again.