Ticket #10774: template-media.diff

File template-media.diff, 3.2 KB (added by Alex Gaynor, 16 years ago)
  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index e25f619..381fdf4 100644
    a b class Media(StrAndUnicode):  
    7575    def __getitem__(self, name):
    7676        "Returns a Media object that only contains media of the given type"
    7777        if name in MEDIA_TYPES:
    78             return Media(**{name: getattr(self, '_' + name)})
     78            return Media(**{str(name): getattr(self, '_' + name)})
    7979        raise KeyError('Unknown media type "%s"' % name)
    8080
    8181    def add_js(self, data):
    class NullBooleanSelect(Select):  
    422422
    423423    def value_from_datadict(self, data, files, name):
    424424        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,
    430430                False: False}.get(value, None)
    431431
    432432    def _has_changed(self, initial, data):
  • tests/regressiontests/forms/media.py

    diff --git a/tests/regressiontests/forms/media.py b/tests/regressiontests/forms/media.py
    index d05db1f..c6dc8f0 100644
    a b media_tests = r"""  
    286286# Multiwidget media handling
    287287###############################################################
    288288
    289 # MultiWidgets have a default media definition that gets all the 
     289# MultiWidgets have a default media definition that gets all the
    290290# media from the component widgets
    291291>>> class MyMultiWidget(MultiWidget):
    292292...     def __init__(self, attrs=None):
    293293...         widgets = [MyWidget1, MyWidget2, MyWidget3]
    294294...         super(MyMultiWidget, self).__init__(widgets, attrs)
    295            
     295
    296296>>> mymulti = MyMultiWidget()
    297 >>> print mymulti.media   
     297>>> print mymulti.media
    298298<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
    299299<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
    300300<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
    media_tests = r"""  
    355355<script type="text/javascript" src="/path/to/js4"></script>
    356356<script type="text/javascript" src="/some/form/javascript"></script>
    357357
     358# Media works in templates
     359>>> from django.template import Template, Context
     360>>> Template("{{ form.media.js }}{{ form.media.css }}").render(Context({'form': f3}))
     361u'<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
    358370>>> settings.MEDIA_URL = ORIGINAL_MEDIA_URL
    359 """
    360  No newline at end of file
     371"""
Back to Top