# -*- coding: utf-8 # Copyright (c) 2008, iCamp Consortium # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. from OFS.Folder import Folder from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from Globals import Persistent, Acquisition from utils import cookString from zope.interface import implements import zope from zope.component import getUtility from ZPublisher.HTTPRequest import FileUpload from interfaces import IToolsManager, ITool, IAffordanceManager from Tool import Tool class ToolsManager(Persistent, Folder, Acquisition.Implicit): implements(IToolsManager) meta_type = 'ToolsManager' id = 'tools' def getToolTitleById(self, tid): return getattr(self, tid).title def getTools(self): return self.objectValues('Tool') def getToolIds(self): return self.objectIds('Tool') def listTools(self): """ list tools for "Tools" tab. {'toolid': {'title':'Yahoo!', 'img'} } """ res = [] for t in self.getTools(): if t.getHasThumbnail(): turl = 'tools/'+t.id+'/getThumbnail' else: turl = '++resource++styles/tool_default.png' res.append({'id': t.id.encode('utf-8'), 'title': t.title.encode('utf-8'), 'img': turl}) return str(res).replace("'", '"') def newToolForm(self): """ new Tool adding form """ # 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 += '