Ticket #11865: form-media-raw-javascript.patch
File form-media-raw-javascript.patch, 1.5 KB (added by , 15 years ago) |
---|
-
django/forms/widgets.py
29 29 'SplitDateTimeWidget', 30 30 ) 31 31 32 MEDIA_TYPES = ('css', 'js')32 MEDIA_TYPES = ('css', 'js', 'raw_js') 33 33 34 34 class Media(StrAndUnicode): 35 35 def __init__(self, media=None, **kwargs): … … 40 40 41 41 self._css = {} 42 42 self._js = [] 43 self._raw_js = [] 43 44 44 45 for name in MEDIA_TYPES: 45 46 getattr(self, 'add_' + name)(media_attrs.get(name, None)) … … 57 58 def render_js(self): 58 59 return [u'<script type="text/javascript" src="%s"></script>' % self.absolute_path(path) for path in self._js] 59 60 61 def render_raw_js(self): 62 if self._raw_js: 63 return [u'<script type="text/javascript">\n%s\n</script>' % u'\n'.join(self._raw_js)] 64 else: 65 return [] 66 60 67 def render_css(self): 61 68 # To keep rendering order consistent, we can't just iterate over items(). 62 69 # We need to sort the keys, and iterate over the sorted list. … … 82 89 if data: 83 90 self._js.extend([path for path in data if path not in self._js]) 84 91 92 def add_raw_js(self, data): 93 if data: 94 self._raw_js.extend([script for script in data if script and script not in self._raw_js]) 95 85 96 def add_css(self, data): 86 97 if data: 87 98 for medium, paths in data.items():