Back to index

plone3  3.1.7
contentUsesKupu.py
Go to the documentation of this file.
00001 ## Script (Python) "contentUsesKupu"
00002 ##title=Allow graceful degradation if content is not text/html
00003 ##bind container=container
00004 ##bind context=context
00005 ##bind namespace=
00006 ##bind script=script
00007 ##bind subpath=traverse_subpath
00008 ##parameters=fieldname
00009 from Products.CMFCore.utils import getToolByName
00010 
00011 from Products.CMFCore.utils import getToolByName
00012 tool = getToolByName(context, 'kupu_library_tool')
00013 REQUEST = context.REQUEST
00014 
00015 # If the user doesn't have kupu configured then we can't use it.
00016 if not tool.isKupuEnabled(REQUEST=REQUEST, context=context, fieldName=fieldname):
00017     return False
00018 
00019 if not fieldname:
00020     return True # Non AT content always tries to use kupu
00021 
00022 if fieldname == REQUEST.form.get('kupu.convert', ''):
00023     return True
00024 if fieldname == REQUEST.form.get('kupu.suppress', ''):
00025     return False
00026 
00027 if not hasattr(context, 'getField'):
00028     return True
00029     
00030 field = context.getField(fieldname)
00031 if not field:
00032   return True
00033 text_format = REQUEST.get('%s_text_format' % fieldname, context.getContentType(fieldname))
00034 content = field.getEditAccessor(context)()
00035 try:
00036     if content.startswith('<!--'):
00037         return False
00038 except AttributeError:
00039     return False
00040 return len(content)==0 or 'html' in text_format.lower()
00041