Annotation of kupuMPIWG/plone/kupu_plone_layer/contentUsesKupu.py, revision 1.1.1.1

1.1       dwinter     1: ## Script (Python) "contentUsesKupu"
                      2: ##title=Allow graceful degradation if content is not text/html
                      3: ##bind container=container
                      4: ##bind context=context
                      5: ##bind namespace=
                      6: ##bind script=script
                      7: ##bind subpath=traverse_subpath
                      8: ##parameters=fieldname
                      9: from Products.CMFCore.utils import getToolByName
                     10: 
                     11: from Products.CMFCore.utils import getToolByName
                     12: tool = getToolByName(context, 'kupu_library_tool')
                     13: REQUEST = context.REQUEST
                     14: 
                     15: # If the user doesn't have kupu configured then we can't use it.
                     16: if not tool.isKupuEnabled(REQUEST=REQUEST):
                     17:     return False
                     18: 
                     19: if not fieldname:
                     20:     return True # Non AT content always tries to use kupu
                     21: 
                     22: if fieldname == REQUEST.form.get('kupu.convert', ''):
                     23:     return True
                     24: if fieldname == REQUEST.form.get('kupu.suppress', ''):
                     25:     return False
                     26: 
                     27: if not hasattr(context, 'getField'):
                     28:     return True
                     29:     
                     30: field = context.getField(fieldname)
                     31: if not field:
                     32:   return True
                     33: text_format = REQUEST.get('%s_text_format' % fieldname, context.getContentType(fieldname))
                     34: content = field.getEditAccessor(context)()
                     35: 
                     36: return len(content)==0 or 'html' in text_format.lower()
                     37: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>