def render(self, name, value, attrs=None): if value is None: value = '' value = force_unicode(value) final_attrs = self.build_attrs(attrs) final_attrs['name'] = name assert 'id' in final_attrs, "TinyMCE widget attributes must contain 'id'" mce_config = tinymce.settings.DEFAULT_CONFIG.copy() mce_config.update(get_language_config(self.content_language)) if tinymce.settings.USE_FILEBROWSER: mce_config['file_browser_callback'] = "djangoFileBrowser" mce_config.update(self.mce_attrs) mce_config['mode'] = 'exact' mce_config['elements'] = final_attrs['id'] mce_config['strict_loading_mode'] = 1 mce_json = simplejson.dumps(mce_config) html = [u'<textarea%s>%s</textarea>' % (flatatt(final_attrs), escape(value))] if tinymce.settings.USE_COMPRESSOR: compressor_config = { 'plugins': mce_config.get('plugins', ''), 'themes': mce_config.get('theme', 'advanced'), 'languages': mce_config.get('language', ''), 'diskcache': True, 'debug': False, } compressor_json = simplejson.dumps(compressor_config) html.append(u'<script type="text/javascript">tinyMCE_GZ.init(%s)</script>' % compressor_json) html.append(u'<script type="text/javascript">tinyMCE.init(%s)</script>' % mce_json) return mark_safe(u'\n'.join(html))
def render(self, name, value=None, attrs={}): final_attrs = self.build_attrs(attrs, name=name) # Handles different types of choices if isinstance(self.choices, list): source = simplejson.dumps(self.choices) elif isinstance(self.choices, str): source = "'{0}'".format(escape(self.choices)) elif isinstance(self.choices, tuple): # assumes tuple will be 2-item choice tuples (as in the docs) try: ## This sets the displayed values # If you have (for example) "fruit" tuples like (('apples', 'apples'),), then you can # just use item[0] for the "label" # The below set up is useful for displaying the human-readable format, and inserting # the value that will go into the database. For instance, (('FL', 'Florida'),) will # display "Florida" but insert "FL" into the field. source = simplejson.dumps([{"label": "{0}".format(item[1]), "value": "{0}".format(item[0])} for item in self.choices]) except IndexError: raise ValueError("choices tuple is not valid") else: raise ValueError("choices type is not valid") options = '' if self.options: options += ",{0}".format(self.options) # for passing add'l autocomplete options if value: value = force_unicode(value) final_attrs['value'] = escape(value) if not self.attrs.has_key('id'): final_attrs['id'] = 'id_{0}'.format(name) return mark_safe(u'''<input type="text" name="{0}" id="{1}" {2}> <script type="text/javascript"> $('#{1}').autocomplete({{source:{3}{4}}}); </script>'''.format(name, flatatt(final_attrs), final_attrs['id'], source, options))
def render(self, name, value, attrs=None): value = value or u'' value = force_unicode(value) final_attrs = self.build_attrs(attrs) final_attrs['name'] = name config = self.get_config(name) html = [u'<textarea%s>%s</textarea>' % (flatatt(final_attrs), escape(value))] html.append(u'<input type="hidden" name="%(name)s_img" id="%(name)s_img">' % {'name': name}) html.append(config) return mark_safe(u'\n'.join(html))
def render(self, name, value, attrs=None): if value is None: value = '' value = force_unicode(value) final_attrs = self.build_attrs(attrs) final_attrs['name'] = name assert 'id' in final_attrs, "TinyMCE widget attributes must contain 'id'" mce_config = tinymce.settings.DEFAULT_CONFIG.copy() mce_config.update(get_language_config(self.content_language)) if tinymce.settings.USE_FILEBROWSER: mce_config['file_browser_callback'] = "djangoFileBrowser" mce_config.update(self.mce_attrs) mce_config['mode'] = 'exact' mce_config['elements'] = final_attrs['id'] mce_config['strict_loading_mode'] = 1 mce_json = simplejson.dumps(mce_config) html = [ u'<textarea%s>%s</textarea>' % (flatatt(final_attrs), escape(value)) ] if tinymce.settings.USE_COMPRESSOR: compressor_config = { 'plugins': mce_config.get('plugins', ''), 'themes': mce_config.get('theme', 'advanced'), 'languages': mce_config.get('language', ''), 'diskcache': True, 'debug': False, } compressor_json = simplejson.dumps(compressor_config) html.append( u'<script type="text/javascript">tinyMCE_GZ.init(%s)</script>' % compressor_json) html.append( u'<script type="text/javascript">tinyMCE.init(%s)</script>' % mce_json) return mark_safe(u'\n'.join(html))