# -*- coding: utf-8 """ ProxyFile """ __version__ = "$Revision$"[11:-2] import Globals from Products.iva.WebtopItem import WebtopItem import OFS,time from AccessControl import ClassSecurityInfo from Products.iva.common import perm_view class ProxyFile(WebtopItem, OFS.SimpleItem.Item): """ ProxyFile """ meta_type = 'WebtopProxyFile' security = ClassSecurityInfo() def __init__(self, parent, name, params): """ Construct object """ WebtopItem.__init__(self, parent, name) self._params = params self._cached_time = 0 self._cached_content = '' self._is_dead_object = 0 def manage_afterAdd(self, item, container): WebtopItem.manage_afterAdd(self, item, container) security.declareProtected(perm_view, 'index_html') def index_html(self, REQUEST): """ index html """ if not self._cached_content and not self._is_dead_object: # get content self._getcontent() else: if time.time()-self._cached_time > 200 and not self._is_dead_object: #update content self._getcontent() return self.wt_proxy_view(self, REQUEST) def _getcontent(self): from SOAPpy import WSDL server = WSDL.Proxy(self._params['main_wsdl']) auth = WSDL.Proxy(self._params['sess_wsdl']) sessID = auth.createAnonymousSession() res = server.setResultsFormat(sessID, 'SingleObject') if not res: return query = '' query += '' query += '%s' % self._params['guid'] query += '' res = server.synchronousQuery(sessID, query, 0) from xml.dom.minidom import parseString from Products.iva.ImportExport import get_text r = parseString(res) r.normalize() cc_elem = r.getElementsByTagName('object')[0] content = get_text(cc_elem) self._cached_content = content self._cached_time = time.time() def get_size(self): return 1 security.declareProtected(perm_view, 'get_rendered_body') def get_rendered_body(self): """ rendered body """ return self._cached_content Globals.InitializeClass(ProxyFile) # EOF