diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index e25f619..381fdf4 100644
a
|
b
|
class Media(StrAndUnicode):
|
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): |
… |
… |
class NullBooleanSelect(Select):
|
422 | 422 | |
423 | 423 | def value_from_datadict(self, data, files, name): |
424 | 424 | value = data.get(name, None) |
425 | | return {u'2': True, |
426 | | True: True, |
427 | | 'True': True, |
428 | | u'3': False, |
429 | | 'False': False, |
| 425 | return {u'2': True, |
| 426 | True: True, |
| 427 | 'True': True, |
| 428 | u'3': False, |
| 429 | 'False': False, |
430 | 430 | False: False}.get(value, None) |
431 | 431 | |
432 | 432 | def _has_changed(self, initial, data): |
diff --git a/tests/regressiontests/forms/media.py b/tests/regressiontests/forms/media.py
index d05db1f..c6dc8f0 100644
a
|
b
|
media_tests = r"""
|
286 | 286 | # Multiwidget media handling |
287 | 287 | ############################################################### |
288 | 288 | |
289 | | # MultiWidgets have a default media definition that gets all the |
| 289 | # MultiWidgets have a default media definition that gets all the |
290 | 290 | # media from the component widgets |
291 | 291 | >>> class MyMultiWidget(MultiWidget): |
292 | 292 | ... def __init__(self, attrs=None): |
293 | 293 | ... widgets = [MyWidget1, MyWidget2, MyWidget3] |
294 | 294 | ... super(MyMultiWidget, self).__init__(widgets, attrs) |
295 | | |
| 295 | |
296 | 296 | >>> mymulti = MyMultiWidget() |
297 | | >>> print mymulti.media |
| 297 | >>> print mymulti.media |
298 | 298 | <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" /> |
299 | 299 | <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> |
300 | 300 | <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> |
… |
… |
media_tests = r"""
|
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 | | """ |
360 | | No newline at end of file |
| 371 | """ |