import cElementTree as ET from cStringIO import StringIO from Products.Five import BrowserView as BaseView from zope.interface import implements from zope.component import getUtility from AccessControl import getSecurityManager from Products.iva.interfaces import IIVAPlugin from interfaces import IWaramu, IWaramuTool from WaramuTool import WaramuTool class BaseBase(BaseView): """ base view """ def registerVisit(self): pass def getWaramuURL(self): return getUtility(IWaramuTool, name="waramutool").getWaramuURL() class UserView(BaseBase): """ waramu manager view """ _msg = '' _sterm = '' _results = [] def getMyResources(self): w = getUtility(IWaramuTool, name="waramutool") uname = getSecurityManager().getUser() q = "<_owner>"+str(uname)+"" return w._listIdentifiers(q) def getSearchTerm(self): return self._sterm def dosearch(self): req = self.request n = self.context.restrictedTraverse('results.html') if req.get('searchButton'): st = req.get('searchText') n._sterm = st root = ET.Element('query') root.set("allcatalogs", "1") delem = ET.SubElement(root, '_fulltext') delem.text = st.decode('utf-8') q = StringIO() tree = ET.ElementTree(root) tree.write(q) q.seek(0) q = q.read() w = getUtility(IWaramuTool, name="waramutool") n._results = w._listIdentifiers(q) self.request.RESPONSE.setBase(self.context.absolute_url()) return n() def getResults(self): return self._results def getResource(self, rid): """ get resource by rid """ w = getUtility(IWaramuTool, name="waramutool") return w._getResource(rid) class UserResourceView(BaseBase): """ resource view """ _rid = None _obj = None def show(self): r = self.request.get('rid') if not r: return '' n = self.context.restrictedTraverse('resource_view.html') w = getUtility(IWaramuTool, name="waramutool") n._obj = w._getResource(r) n._rid = r self.request.RESPONSE.setBase(self.context.absolute_url()) return n() def getResource(self): return self._obj def getAttachmentsList(self): w = getUtility(IWaramuTool, name="waramutool") atlist = w._listAttachments(self._rid) print atlist return atlist class WaramuConfigure(BaseBase): """ waramu manager view """ _msg = '' def saver(self): req = self.request if req.get('saveWaramu'): wt = getUtility(IWaramuTool, name="waramutool") wt._saveOptions(self.request) wt._connect() elif req.get('openConnectionButton'): wt = getUtility(IWaramuTool, name="waramutool") wt._connect() elif req.get('closeButton'): wt = getUtility(IWaramuTool, name="waramutool") wt._disconnect() n = self.context.restrictedTraverse('manage-waramu') n._msg = 'OK' self.request.RESPONSE.setBase(self.context.absolute_url()) return n() def isConnected(self): wt = getUtility(IWaramuTool, name="waramutool") return wt.isConnected() def getMessage(self): return self._msg def getWaramuSuffix(self): return getUtility(IWaramuTool, name="waramutool").getWaramuSuffix() def isVisible(self): return getUtility(IWaramuTool, name="waramutool").isVisible() def getWaramuLocation(self): return getUtility(IWaramuTool, name="waramutool").getWaramuLocation() def getWaramuUser(self): return getUtility(IWaramuTool, name="waramutool").getWaramuUser()