Ticket #17556: media_inherit.2.patch

File media_inherit.2.patch, 1.7 KB (added by Roman Gladkov, 12 years ago)
  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index 061988c..06132c6 100644
    a b try:  
    1111    from urllib.parse import urljoin
    1212except ImportError:     # Python 2
    1313    from urlparse import urljoin
     14from inspect import getmembers
    1415
    1516from django.conf import settings
    1617from django.forms.util import flatatt, to_current_timezone
    MEDIA_TYPES = ('css','js')  
    3637class Media(object):
    3738    def __init__(self, media=None, **kwargs):
    3839        if media:
    39             media_attrs = media.__dict__
     40            media_attrs = dict(getmembers(media))
    4041        else:
    4142            media_attrs = kwargs
    4243
  • tests/regressiontests/forms/tests/media.py

    diff --git a/tests/regressiontests/forms/tests/media.py b/tests/regressiontests/forms/tests/media.py
    index c492a1e..028ff6b 100644
    a b class FormsMediaTestCase(TestCase):  
    285285<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    286286<script type="text/javascript" src="/path/to/js4"></script>""")
    287287
     288        class BaseMedia:
     289            css = {"all": ["/path/to/css"]}
     290
     291        class ExtendWidget(TextInput):
     292            class Media(BaseMedia):
     293                js = ["/path/to/js"]
     294
     295        extend_widget = ExtendWidget()
     296
     297        self.assertEqual(str(extend_widget.media), """<link href="/path/to/css" type="text/css" media="all" rel="stylesheet" />
     298<script type="text/javascript" src="/path/to/js"></script>""")
     299
    288300    def test_media_inheritance_single_type(self):
    289301        # A widget can enable inheritance of one media type by specifying extend as a tuple
    290302        class MyWidget1(TextInput):
Back to Top