コード例 #1
0
    def setDynamicSkin(self):
        skin = self.request['skin']

        manager = IDynamicViewManager(self.context)
        manager.setSkin(skin)

        self.context.plone_utils.addPortalMessage(_(u'Skin changed.'))
        self.request.response.redirect(self.context.REQUEST['HTTP_REFERER'])
コード例 #2
0
    def afterSetUp(self):
        super(FunctionalTestCase, self).afterSetUp()
        self.loginAsPortalOwner()
        wtool = getToolByName(self.portal, 'portal_workflow')
        
        # Menu Folder
        id = self.portal.invokeFactory('Folder', 'menu')
        ob = getattr(self.portal, id)
        ob.setTitle('Menu folder')
        wtool.doActionFor(ob, 'publish')
        menu = ob
        self.menu = menu
        
        # First item in menu: an internal link to home
        id = menu.invokeFactory('Link', 'home-link')
        ob = getattr(menu, id)
        ob.setTitle('Home')
        ob.setRemoteUrl('/')
        wtool.doActionFor(ob, 'publish')
        elink = ob

        # Get image file
        pkg_home = Common.package_home({'__name__': 'collective.collage.megamenu'})
        samplesdir = os.path.join(pkg_home, 'tests', 'samples')
        image_file = file(os.path.join(samplesdir, 'test_image.png')).read()

        # Image
        id = self.portal.invokeFactory('Image', 'image')
        ob = getattr(self.portal, id)
        ob.setTitle('Test image')
        ob.setDescription('Dummy description for image')
        ob.setImage(image_file)
        # Image is automatically published
        image = ob
        
        # News item with image
        id = self.portal.invokeFactory('News Item', 'news-item')
        ob = getattr(self.portal, id)
        ob.setTitle('Test news item')
        ob.setDescription('Dummy description for news item')
        ob.setImage(image_file)
        wtool.doActionFor(ob, 'publish')
        ni = ob
        
        # Page (Document)
        id = self.portal.invokeFactory('Document', 'doc')
        ob = getattr(self.portal, id)
        ob.setTitle('Test document')
        ob.setDescription('Dummy description for document')
        wtool.doActionFor(ob, 'publish')
        doc = ob
        
        # Folder 1
        id = self.portal.invokeFactory('Folder', 'folder-1')
        ob = getattr(self.portal, id)
        ob.setTitle('Test folder #1')
        ob.setDescription('Dummy description for folder 1')
        wtool.doActionFor(ob, 'publish')
        folder1 = ob

        # Folder 2
        id = self.portal.invokeFactory('Folder', 'folder-2')
        ob = getattr(self.portal, id)
        ob.setTitle('Test folder #2')
        ob.setDescription('Dummy description for folder 2')
        wtool.doActionFor(ob, 'publish')
        folder2 = ob
        
        # External link
        id = self.portal.invokeFactory('Link', 'external-link')
        ob = getattr(self.portal, id)
        ob.setTitle('External link')
        ob.setDescription('External link to plone.org')
        ob.setRemoteUrl('http://plone.org/')
        wtool.doActionFor(ob, 'publish')
        elink = ob
        
        # Internal link
        id = self.portal.invokeFactory('Link', 'internal-link')
        ob = getattr(self.portal, id)
        ob.setTitle('Internal link')
        ob.setDescription('Internal link to no-where')
        ob.setRemoteUrl('/no-where')
        wtool.doActionFor(ob, 'publish')
        ilink = ob

        # Pre-build a Collage with aliases for each of the just created objects
        # and set the layout
        id = menu.invokeFactory('Collage', 'collage')
        collage = getattr(menu, id)
        collage.setTitle('Collage')
        wtool.doActionFor(collage, 'publish')
        self.collage = collage

        # Row & first column
        id = collage.invokeFactory('CollageRow', '1')
        row = getattr(collage, id)
        manager = IDynamicViewManager(row)
        manager.setLayout('menu')
        id = row.invokeFactory('CollageColumn', '1')
        column = getattr(row, id)
        manager = IDynamicViewManager(column)
        manager.setLayout('menu')
        
        # Alias for image
        id = column.invokeFactory('CollageAlias', 'alias-1')
        alias1 = getattr(column, id)
        alias1.set_target(image.UID())
        manager = IDynamicViewManager(alias1)
        manager.setLayout('menu')
        manager.setSkin('collage-megamenu-highlight')

        # Alias for document
        id = column.invokeFactory('CollageAlias', 'alias-2')
        alias2 = getattr(column, id)
        alias2.set_target(doc.UID())
        manager = IDynamicViewManager(alias2)
        manager.setLayout('menu')
        manager.setSkin('collage-megamenu-title')
        
        # Alias folder 1
        id = column.invokeFactory('CollageAlias', 'alias-3')
        alias3 = getattr(column, id)
        alias3.set_target(folder1.UID())
        manager = IDynamicViewManager(alias3)
        manager.setLayout('menu')

        # Alias for folder 2
        id = column.invokeFactory('CollageAlias', 'alias-4')
        alias4 = getattr(column, id)
        alias4.set_target(folder2.UID())
        manager = IDynamicViewManager(alias4)
        manager.setLayout('menu')
        
        # Alias for external link
        id = column.invokeFactory('CollageAlias', 'alias-5')
        alias5 = getattr(column, id)
        alias5.set_target(elink.UID())
        manager = IDynamicViewManager(alias5)
        manager.setLayout('menu')

        # Alias for internal link
        id = column.invokeFactory('CollageAlias', 'alias-6')
        alias6 = getattr(column, id)
        alias6.set_target(ilink.UID())
        manager = IDynamicViewManager(alias6)
        manager.setLayout('menu') 
        
        # Second column to add an intro layout
        id = row.invokeFactory('CollageColumn', '2')
        column = getattr(row, id)
        manager = IDynamicViewManager(column)
        manager.setLayout('menu')
        # Alias for news item intro
        id = column.invokeFactory('CollageAlias', 'alias-7')
        alias7 = getattr(column, id)
        alias7.set_target(ni.UID())
        manager = IDynamicViewManager(alias7)
        manager.setLayout('intro')
        
        # Alternate menu with just one link
        id = self.portal.invokeFactory('Folder', 'other-menu')
        ob = getattr(self.portal, id)
        ob.setTitle('Alternative menu')
        wtool.doActionFor(ob, 'publish')
        self.other_menu = ob
        
        # Another internal link
        id = self.other_menu.invokeFactory('Link', 'another-link')
        ob = getattr(self.other_menu, id)
        ob.setTitle('Another link')
        ob.setDescription('Internal link to somewhere')
        ob.setRemoteUrl('/somewhere')
        wtool.doActionFor(ob, 'publish')