def refreshPortlet(self, portlethash, **kw): # put parameters on the request, by saving the original context self.request.form, orig_form = kw, self.request.form # Prepare the portlet and render the data info = unhashPortletInfo(portlethash) manager = getUtility(IPortletManager, info['manager']) assignment = assignment_from_key(context = self.context, manager_name = info['manager'], category = info['category'], key = info['key'], name = info['name']) renderer = getMultiAdapter( (self.context, self.request, self.view, manager, assignment.data), IPortletRenderer ) renderer = renderer.__of__(self.context) renderer.update() if IDeferredPortletRenderer.providedBy(renderer): # if this is a deferred load, prepare now the data renderer.deferred_update() result = renderer.render() # Revert the original request self.request.form = orig_form # Command the replacement wrapper_id = 'portletwrapper-%s' % portlethash ksscore = self.getCommandSet('core') ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector(wrapper_id), result)
def testGetPortletFromContext(self): mapping = getMultiAdapter((self.portal, self.manager), IPortletAssignmentMapping) c = classic.Assignment() mapping['foo'] = c path = '/'.join(self.portal.getPhysicalPath()) a = assignment_from_key(self.portal, u'plone.leftcolumn', CONTEXT_CATEGORY, path, 'foo') self.assertEqual(c, a)
def __call__(self): """Return the rendered contents of the portlet specified.""" # portletHash is built into plone.portlets.utils.hashPortletInfo # like this: # concat_txt = '%(manager)s\n%(category)s\n%(key)s\n%(name)s' % info portlethash = self.data.get('portlet_hash') # Prepare the portlet and render the data info = unhashPortletInfo(portlethash) manager = getUtility(IPortletManager, info['manager']) assignment = assignment_from_key(context=self.context, manager_name=info['manager'], category=info['category'], key=info['key'], name=info['name']) renderer = getMultiAdapter( (self.context, self.request, self, manager, assignment.data), IPortletRenderer) renderer = renderer.__of__(self.context) # This is required by some portlets and not set by # the 'portlet-renderer' helper view: renderer.__portlet_metadata__ = info renderer.update() if IDeferredPortletRenderer.providedBy(renderer): # if this is a deferred load, prepare now the data renderer.deferred_update() return u"<html><body>%s</body></html>" % renderer.render()
def testGetPortletFromContextUnicodePath(self): """Do not fail, if path is a unicode object. plone.portlets.utils.unhashPortletInfo returns a unicode path key. """ mapping = getMultiAdapter((self.portal, self.manager), IPortletAssignmentMapping) c = classic.Assignment() mapping['foo'] = c path = u'/'.join(self.portal.getPhysicalPath()) a = assignment_from_key(self.portal, u'plone.leftcolumn', CONTEXT_CATEGORY, path, 'foo') self.assertEqual(c, a)
def _get_portlet(self): portlet_hash = self.request.get('hash') info = unhashPortletInfo(portlet_hash) return assignment_from_key( context=self.context, manager_name=info['manager'], category=info['category'], key=info['key'], name=info['name'])
def _get_portlet(self): portlet_hash = self.request.get("hash") info = unhashPortletInfo(portlet_hash) return assignment_from_key( context=self.context, manager_name=info["manager"], category=info["category"], key=info["key"], name=info["name"], )
def get_column_and_portlet(context, portlet_info): # get column column_manager = getUtility(IPortletManager, name=portlet_info['manager']) userid = context.portal_membership.getAuthenticatedMember().getId() column = column_manager.get(USER_CATEGORY, {}).get(userid, {}) # get portlet portlet = column.get(portlet_info['name']) if not portlet: portlet = assignment_from_key(context, portlet_info['manager'], portlet_info['category'], portlet_info['key'], portlet_info['name']) return column, portlet
def getPortletRenderer(self): portlethash = self.request.get('portlethash', '') info = unhashPortletInfo(portlethash) manager = getUtility(IPortletManager, info['manager']) assignment = assignment_from_key(context = self.context, manager_name = info['manager'], category = info['category'], key = info['key'], name = info['name']) renderer = getMultiAdapter( (self.context, self.request, self, manager, assignment.data), IPortletRenderer ) return renderer.__of__(self.context)
def render_portlet(self, portlethash, **kw): # Prepare the portlet and render the data info = unhashPortletInfo(portlethash) manager = getUtility(IPortletManager, info['manager']) assignment = assignment_from_key(context=self.context, manager_name=info['manager'], category=info['category'], key=info['key'], name=info['name']) renderer = getMultiAdapter( (self.context, self.request, self, manager, assignment.data), IPortletRenderer) renderer = renderer.__of__(self.context) renderer.update() if IDeferredPortletRenderer.providedBy(renderer): # if this is a deferred load, prepare now the data renderer.deferred_update() return renderer.render()
def render_portlet(self, portlethash, **kw): # Prepare the portlet and render the data info = unhashPortletInfo(portlethash) manager = getUtility(IPortletManager, info["manager"]) assignment = assignment_from_key( context=self.context, manager_name=info["manager"], category=info["category"], key=info["key"], name=info["name"], ) renderer = getMultiAdapter((self.context, self.request, self, manager, assignment.data), IPortletRenderer) renderer = renderer.__of__(self.context) renderer.update() if IDeferredPortletRenderer.providedBy(renderer): # if this is a deferred load, prepare now the data renderer.deferred_update() return renderer.render()
def __call__(self, portlethash, uid): """Expand the navtree at a given UID for a given portlet. """ rt=getToolByName(self.context, "reference_catalog") root=rt.lookupObject(uid) info=unhashPortletInfo(portlethash) assignment=assignment_from_key(self.context, info["manager"], info["category"], info["key"], info["name"]) queryBuilder = getMultiAdapter((root, assignment), INavigationQueryBuilder) strategy = getMultiAdapter((aq_inner(self.context), assignment), INavtreeStrategy) strategy = DecorateStrategy(root, strategy) query=queryBuilder() data=buildFolderTree(root, query=query, strategy=strategy) html=self.recurse(children=data.get('children', []), level=1, bottomLevel=assignment.bottomLevel) return html.encode('utf8')
def testGetPortletFromUserCategory(self): c = classic.Assignment() self.cat[user_name]['foo'] = c a = assignment_from_key(self.portal, u'plone.leftcolumn', USER_CATEGORY, user_name, 'foo') self.assertEqual(c, a)