from Globals import Persistent from OFS.SimpleItem import SimpleItem from zope.interface import implements from zope.component import getUtility import zope from ZPublisher.HTTPRequest import FileUpload from interfaces import ITool, IAffordanceManager class Tool(Persistent, SimpleItem): """ Affordance class """ implements(ITool) meta_type = "Tool" def __init__(self, id, title): self.id = id self.title = title self._affData = {} self.hasThumbnail = False def getAffordanceData(self, id): """ get tool's affordance value. id is the affordance's id""" return self._affData.get(id, 0) def setAffordanceData(self, afid, val): vv = int(val) if vv > 10: raise 'Too big value!' self._affData[afid] = vv def setHasThumbnail(self, val): self.hasThumbnail = val def getHasThumbnail(self): return getattr(self, 'hasThumbnail', False) def getDetailedView(self): """ returns a detailed view of Tool. HTML """ # general parameters left = '
' sch = zope.schema.getFields(ITool) # l.order # lres = [] for x in sch.keys(): f = sch.get(x) ltmp = "" ltmp += '
' ltmp += '
'+f.title.encode('utf-8')+"
" ltmp += '
' ltmp += '
'+f.description.encode('utf-8')+"
" if 'TextLine' in str(f): ltmp += '
' elif 'Text' in str(f): ltmp += '