Back to index

plone3  3.1.7
convertContentForKupu.py
Go to the documentation of this file.
00001 ## Script (Python) "convertContentForKupu"
00002 ##title=Convert content to HTML for editing with Kupu
00003 ##bind container=container
00004 ##bind context=context
00005 ##bind namespace=
00006 ##bind script=script
00007 ##bind subpath=traverse_subpath
00008 ##parameters=fieldname, content
00009 from Products.CMFCore.utils import getToolByName
00010 from Products.PythonScripts.standard import structured_text, newline_to_br
00011 
00012 field = context.getField(fieldname)
00013 text_format = context.REQUEST.get('%s_text_format' % fieldname, context.getContentType(fieldname))
00014 
00015 if len(content)==0 or 'html' in text_format.lower():
00016     if isinstance(content, unicode):
00017         try:
00018             encoding = context.getCharset()
00019         except AttributeError:
00020             encoding = 'utf8'
00021         content = content.encode(encoding)
00022 
00023     return str(content)
00024 
00025 transforms = getToolByName(context, 'portal_transforms')
00026 
00027 converted = transforms.convertToData('text/html', content, mimetype=text_format)
00028 if converted is not None:
00029     return converted
00030 
00031 return content