示例#1
0
def addProjectNavPortlet(obj, event):
    """Event handler triggered when adding a project folder. This will add
    the project navigator portlet automatically.
    """

    parent = aq_parent(obj)
    if IProjectFolder.providedBy(parent):
        return

    # A portlet manager is a plugin to a column
    column = getUtility(IPortletManager, name=u"plone.leftcolumn")

    # We multi-adapt the object and the column to an assignment mapping,
    # which acts like a dict where we can put portlet assignments
    manager = getMultiAdapter((
        obj,
        column,
    ), IPortletAssignmentMapping)

    # We then create the assignment and put it in the assignment manager,
    # using the default name-chooser to pick a suitable name for us.
    assignment = navigation.Assignment(name=u"项目导航",
                                       root_uid=obj.UID(),
                                       topLevel=0)
    chooser = INameChooser(manager)
    manager[chooser.chooseName(None, assignment)] = assignment
示例#2
0
    def test_no_project(self):
        portal = self.layer['portal']
         
        login(portal, "member1")
        member = self.membership.getAuthenticatedMember()

        r = self.renderer(
                          context=portal, assignment=navigation.Assignment(topLevel=0,
                                                                           root_uid=portal['folder1'].UID()))
        self.assertTrue(r.available)
        logout()
        login(portal, "member2")
        import pdb
        pdb.set_trace()        
        r = self.renderer(context=portal, assignment=navigation.Assignment(topLevel=0))
        self.assertFalse(r.available)        
示例#3
0
 def test_anonymous(self):
     portal = self.layer['portal']
      
     member = self.membership.getAuthenticatedMember()        
     logout()         
     r = self.renderer(context=portal, assignment=navigation.Assignment())
     self.assertFalse(r.available)
示例#4
0
    def testRenderer(self):
        context = self.layer['portal']
        request = self.layer['request']
        
        view = context.restrictedTraverse('@@plone')
        manager = getUtility(IPortletManager, name='plone.rightcolumn', context=context)
        assignment = navigation.Assignment()

        renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
        self.assertTrue(isinstance(renderer, navigation.Renderer))
示例#5
0
    def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
        portal = self.layer['portal']
         
        context = context or portal
        request = request or self.layer['request']
         
        view = view or portal.restrictedTraverse('@@plone')
         
        manager = manager or getUtility(IPortletManager, name='plone.rightcolumn', context=portal)
        assignment = assignment or navigation.Assignment()
 
        return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
示例#6
0
def add_member_navigator_portlet(context):
    pc = getToolByName(context, "portal_catalog")
    query = {"object_provides": IProjectFolder.__identifier__, "id": "Members"}
    bns = pc(query)
    if len(bns) == 0: return
    obj = bns[0].getObject()
    # column = getUtility(IPortletManager, name=u"plone.leftcolumn")
    column = getUtility(IPortletManager, name=u"plone.rightcolumn")
    # We multi-adapt the object and the column to an assignment mapping,
    # which acts like a dict where we can put portlet assignments
    manager = getMultiAdapter((
        obj,
        column,
    ), IPortletAssignmentMapping)

    # We then create the assignment and put it in the assignment manager,
    # using the default name-chooser to pick a suitable name for us.
    assignment = navigation.Assignment(name=u"工作空间",
                                       root_uid=obj.UID(),
                                       topLevel=0)
    chooser = INameChooser(manager)
    manager[chooser.chooseName(None, assignment)] = assignment
示例#7
0
 def testInterfaces(self):
     portlet = navigation.Assignment()
     self.assertTrue(IPortletAssignment.providedBy(portlet))
     self.assertTrue(IPortletDataProvider.providedBy(portlet.data))