Ticket #9216: widget_assert_list_or_tuple.diff
File widget_assert_list_or_tuple.diff, 2.0 KB (added by , 16 years ago) |
---|
-
tests/regressiontests/forms/media.py
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 ############################################################### 359 # Assertions: js and css attributes need a list or tuple 360 ############################################################### 361 362 # Test Assertion that you need to pass in a tuple or list 363 >>> class MyBrokenCSSWidget(MyWidget1): 364 ... class Media: 365 ... css={'all': 'foo.css'} 366 >>> widget=MyBrokenCSSWidget() 367 >>> unicode(widget.media) 368 Traceback (most recent call last): 369 ... 370 AssertionError: Need tuple or list not <type 'str'>: foo.css 371 372 # Test Assertion JS 373 >>> class MyBrokenJSWidget(MyWidget1): 374 ... class Media: 375 ... js='foo.js' 376 >>> widget=MyBrokenJSWidget() 377 >>> unicode(widget.media) 378 Traceback (most recent call last): 379 ... 380 AssertionError: Need tuple or list not <type 'str'>: foo.js 381 358 382 >>> settings.MEDIA_URL = ORIGINAL_MEDIA_URL -
django/forms/widgets.py
80 80 81 81 def add_js(self, data): 82 82 if data: 83 assert isinstance(data, (tuple, list)), 'Need tuple or list not %s: %s' % (type(data), data) 83 84 self._js.extend([path for path in data if path not in self._js]) 84 85 85 86 def add_css(self, data): 86 87 if data: 87 88 for medium, paths in data.items(): 89 assert isinstance(paths, (tuple, list)), 'Need tuple or list not %s: %s' % (type(paths), paths) 88 90 self._css.setdefault(medium, []).extend([path for path in paths if path not in self._css[medium]]) 89 91 90 92 def __add__(self, other):