from Products.Archetypes.Widget import TextAreaWidget from Products.Archetypes.Registry import registerWidget, registerPropertyType from Products.Archetypes.utils import shasattr from types import StringType from Globals import InitializeClass from AccessControl import ClassSecurityInfo class SourceCodeWidget(TextAreaWidget): _properties = TextAreaWidget._properties.copy() _properties.update({ 'macro' : 'sourcecodewidget', 'helper_js': ("silvercity_shCore.js", "silvercity_shBrushPython.js", "silvercity_shTrigger.js"), 'helper_css': ("SyntaxHighlighter.css",), 'get_language_method': None }) security = ClassSecurityInfo() # todo: should be only on a view security.declarePublic('getLanguage') def getLanguage(self, instance): """Return the language by looking up through get_language_method""" name = self.get_language_method if name is None: raise ValueError, "The get_language_method needs to be defined" if type(name) is StringType and shasattr(instance, name): method = getattr(instance, name) return method() else: raise ValueError, "Can't find the method %s on the object." % name InitializeClass(SourceCodeWidget) registerWidget(SourceCodeWidget, title='Source Code Widget', description=('A widget that displays sou'), used_for=('Products.Archetypes.Field.ReferenceField',) ) registerPropertyType('get_language_method', 'string', SourceCodeWidget)