def test_should_remove_tag_if_context_can_not_be_found(self):
     portal = self.layer['portal']
     rightcol = getUtility(IPortletManager, name=u'plone.rightcolumn', context=portal)
     right = getMultiAdapter((portal, rightcol,), IPortletAssignmentMapping, context=portal)
     
     staticportlet = static.Assignment(header=u"Static Portlet", text=u"TEXT INPUT")
     right[u'staticportlet'] = staticportlet
     
     settings = IPortletAssignmentSettings(staticportlet)
     visible = settings.get('visible', True)
     settings['visible'] = False
     
     class FakeContent:
         def UID(self): return '1'
     page = portal[portal.invokeFactory('Document', 'testpage')]
     hash = portletHash(rightcol, staticportlet, FakeContent())
     field = page.getField('text')
     portletmarkup = portletMarkup(hash)
     field.set(page, portletmarkup, mimetype='text/html')
     page.setTitle('Blah')
     page.reindexObject()
     transaction.commit()
     
     self.browser.open('http://nohost/plone/testpage')
     
     self.failUnless("TEXT INPUT" not in self.browser.contents)
     self.failUnless('<img class="TINYMCEPORTLET mce-only' not in self.browser.contents)
     
 def test_portlet_renders_in_tiny_mce(self):
     portal = self.layer['portal']
     rightcol = getUtility(IPortletManager, name=u'plone.rightcolumn', context=portal)
     right = getMultiAdapter((portal, rightcol,), IPortletAssignmentMapping, context=portal)
     
     staticportlet = static.Assignment(header=u"Static Portlet", text=u"TEXT INPUT")
     right[u'staticportlet'] = staticportlet
     
     settings = IPortletAssignmentSettings(staticportlet)
     visible = settings.get('visible', True)
     settings['visible'] = False
     
     page = portal[portal.invokeFactory('Document', 'testpage')]
     hash = portletHash(rightcol, staticportlet, portal)
     field = page.getField('text')
     portletmarkup = portletMarkup(hash)
     field.set(page, portletmarkup, mimetype='text/html')
     page.setTitle('Blah')
     page.reindexObject()
     transaction.commit()
     
     self.browser.open('http://nohost/plone/testpage')
     
     self.failUnless("TEXT INPUT" in self.browser.contents)
def Portlets(context):
    site = getSite()

    try:
        req = site.REQUEST
    except AttributeError:
        req = context.REQUEST

    if 'manager' not in req:
        utils = getUtilitiesFor(IPortletManager)
        mng_name = [(n, m) for n, m in utils if 'dashboard' not in n][0][0]
    else:
        mng_name = req.get('manager')

    if 'context' in req:
        context_req = str(req.get('context')).strip()
        mod_context = context.restrictedTraverse(context_req, None)
        if mod_context is None:
            ref_cat = getToolByName(site, 'reference_catalog')
            mod_context = ref_cat.lookupObject(context_req)
        if mod_context:
            context = mod_context

    terms = []
    utils = getUtilitiesFor(IPortletManager)
    for mng_name, pm in [(n, m) for n, m in utils if 'dashboard' not in n]:
        title = _pm_titles.get(mng_name, mng_name)
        manager = getUtility(IPortletManager, name=mng_name, context=context)
        retriever = getMultiAdapter((context, manager), IPortletRetriever)
        for portlet in retriever.getPortlets():
            assignment = portlet['assignment']
            name = '%s - %s' % (title, assignment.__name__)
            value = portletHash(manager, assignment, context)
            terms.append(SimpleTerm(value=value, token=value, title=name))

    return SimpleVocabulary(terms)