def afterSetUp(self):
        """ Adding an OAIServer, a ZCatalog and a ZCatalogHarvester

        """
        manage_addZCatalog(self.app, 'catalog', 'Catalog')
        manage_addOAIServer(self.app, 'oai', title=u'OAI Server')

        manage_addFolder(self.app, 'folder', 'Folder')
        self.app.folder.description = u'Some descr'

        manage_addFolder(self.app, 'folder1', 'Folder1')
        self.app.folder1.description = u'Some descr111'

        self.app.catalog.catalog_object(self.app.folder,
                                        self.app.folder.absolute_url(1))
        self.app.catalog.catalog_object(self.app.folder1,
                                        self.app.folder1.absolute_url(1))

        manage_addZCatalogHarvester(self.app.oai, 'harvester',
                                    title=u'Harvester',
                                    search_meta_types=Folder.meta_type)

        self.server = startZServer()
        self.server_url = 'http://%s:%s/' % (self.server[0],
                                             str(self.server[1]))
Beispiel #2
0
 def _setupFolder(self):
     '''Creates and configures the folder.'''
     from OFS.Folder import manage_addFolder
     manage_addFolder(self.app, folder_name)
     self.folder = getattr(self.app, folder_name)
     self.folder._addRole(user_role)
     self.folder.manage_role(user_role, standard_permissions)
Beispiel #3
0
 def installUi(self):
     '''Installs the user interface.'''
     # Some useful imports
     from OFS.Folder import manage_addFolder
     from OFS.Image import manage_addImage, manage_addFile
     from Products.PythonScripts.PythonScript import PythonScript
     from Products.PageTemplates.ZopePageTemplate import \
          manage_addPageTemplate
     # Delete the existing folder if it existed.
     zopeContent = self.app.objectIds()
     if 'ui' in zopeContent: self.app.manage_delObjects(['ui'])
     manage_addFolder(self.app, 'ui')
     # Browse the physical ui folders (the Appy one and an app-specific, if
     # the app defines one) and create the corresponding objects in the Zope
     # folder. In the case of files having the same name in both folders,
     # the one from the app-specific folder is chosen.
     j = os.path.join
     uiFolders = [j(j(appy.getPath(), 'gen'), 'ui')]
     appUi = j(self.config.diskFolder, 'ui')
     if os.path.exists(appUi): uiFolders.insert(0, appUi)
     for ui in uiFolders:
         for root, dirs, files in os.walk(ui):
             folderName = root[len(ui):]
             # Get the Zope folder that corresponds to this name
             zopeFolder = self.app.ui
             if folderName:
                 for name in folderName.strip(os.sep).split(os.sep):
                     zopeFolder = zopeFolder._getOb(name)
             # Create sub-folders at this level
             for name in dirs:
                 if not hasattr(zopeFolder.aq_base, name):
                     manage_addFolder(zopeFolder, name)
             # Create files at this level
             for name in files:
                 zopeName, ext = os.path.splitext(name)
                 if ext not in ('.pt', '.py'):
                     # In the ZODB, pages and scripts have their name without
                     # their extension.
                     zopeName = name
                 if hasattr(zopeFolder.aq_base, zopeName): continue
                 f = file(j(root, name))
                 if ext in gen.File.imageExts:
                     manage_addImage(zopeFolder, zopeName, f)
                 elif ext == '.pt':
                     manage_addPageTemplate(zopeFolder,zopeName,'',f.read())
                 elif ext == '.py':
                     obj = PythonScript(zopeName)
                     zopeFolder._setObject(zopeName, obj)
                     zopeFolder._getOb(zopeName).write(f.read())
                 else:
                     manage_addFile(zopeFolder, zopeName, f)
                 f.close()
     # Update the home page
     if 'index_html' in zopeContent:
         self.app.manage_delObjects(['index_html'])
     manage_addPageTemplate(self.app, 'index_html', '', homePage)
     # Update the error page
     if 'standard_error_message' in zopeContent:
         self.app.manage_delObjects(['standard_error_message'])
     manage_addPageTemplate(self.app, 'standard_error_message', '',errorPage)
Beispiel #4
0
    def setUp(self):
        self.responseOut = cStringIO.StringIO()
        self.connection = makeConnection()
        try:
            r = self.connection.root()
            a = Application()
            r['Application'] = a
            self.root = a
            self.app = makerequest(self.root, stdout=self.responseOut)
            try: self.app._delObject(TESTFOLDER_NAME)
            except AttributeError: pass
            manage_addFolder(self.app, TESTFOLDER_NAME)
            folder = getattr( self.app, TESTFOLDER_NAME )

            data = string.letters
            manage_addFile( folder, 'file'
                          , file=data, content_type='text/plain')

            self.file = folder.file
            self.data = data

            # Hack, we need a _p_mtime for the file, so we make sure that it
            # has one. We use a subtransaction, which means we can rollback
            # later and pretend we didn't touch the ZODB.
            transaction.commit()
        except:
            self.connection.close()
            raise
Beispiel #5
0
    def _initFolders(self):

        self.connection = makeConnection()
        try:
            r = self.connection.root()
            a = Application()
            r['Application'] = a
            self.root = a
            responseOut = self.responseOut = cStringIO.StringIO()
            self.app = makerequest( self.root, stdout=responseOut )
            manage_addFolder( self.app, 'folder1' )
            manage_addFolder( self.app, 'folder2' )
            folder1 = getattr( self.app, 'folder1' )
            folder2 = getattr( self.app, 'folder2' )

            manage_addFile( folder1, 'file'
                          , file='', content_type='text/plain')

            # Hack, we need a _p_mtime for the file, so we make sure that it
            # has one. We use a subtransaction, which means we can rollback
            # later and pretend we didn't touch the ZODB.
            transaction.commit()
        except:
            self.connection.close()
            raise
        transaction.begin()

        return self.app._getOb( 'folder1' ), self.app._getOb( 'folder2' )
    def testNextPreviousItems(self):
        container = self.portal[self.portal.invokeFactory(self._portal_type, 'case3')]
        for id in range(1, 4):
            container.invokeFactory('Document', 'subDoc%d' % id)

        from OFS.Folder import manage_addFolder
        manage_addFolder(container, 'notacontentishtype')

        for id in range(5, 6):
            container.invokeFactory('Document', 'subDoc%d' % id)

        adapter = INextPreviousProvider(container)
        # text data for next/previous items
        next = adapter.getNextItem(container.subDoc2)
        self.assertEqual(next['id'], 'subDoc3')
        self.assertEqual(next['portal_type'], 'Document')
        self.assertEqual(next['url'], container.subDoc3.absolute_url())
        previous = adapter.getPreviousItem(container.subDoc2)
        self.assertEqual(previous['id'], 'subDoc1')
        self.assertEqual(previous['portal_type'], 'Document')
        self.assertEqual(previous['url'], container.subDoc1.absolute_url())

        # #11234 not contentish contents shouldn't be returned
        # as next or previous content
        next = adapter.getNextItem(container.subDoc3)
        self.assertEqual(next['id'], 'subDoc5')
        previous = adapter.getPreviousItem(container.subDoc5)
        self.assertEqual(previous['id'], 'subDoc3')

        # first item should not have a previous item
        previous = adapter.getPreviousItem(container.subDoc1)
        self.assertEqual(previous, None)
        # last item should not have a next item
        next = adapter.getNextItem(container.subDoc5)
        self.assertEqual(next, None)
    def test_zcatalog(self):
        """ Using the ZCatalog storage
        Test flow:

        Add an OAIHarvester with the local URL of the OAIServer ->
        update it against and check the presence of the OAIRecords.

        Add one folder -> update the OAIServer -> update OAIAggregator ->
        update the specific OAIHarvester and recheck it there is a new OAIRecord
        in the OAIHarvester

        Same ideea after deleting the folder that was added.

        """
        manage_addOAIAggregator(self.app, 'oai_agg', title=u"OAI Aggregator",
                                storage='ZCatalog')
        manage_addOAIHarvester(self.app.oai_agg, 'oai_harv',
                               title=u"Local OAI Server",
                               url=self.server_url + 'oai')
        self.app.oai_agg.update()
        # Has 2 records in it's contents
        self.assertEqual(len(self.app.oai_agg.oai_harv.\
                             objectValues([OAIRecord.meta_type])), 2)

        #Search catalog
        catalog = self.app.oai_agg.getCatalog()
        results = catalog.searchResults(meta_type=OAIRecord.meta_type)
        self.assertEqual(len(results), 2)

        #Adding one folder and repeat the procedure
        manage_addFolder(self.app, 'other_folder', 'Some other folder')
        self.app.other_folder.description = u'This is some kind of description'
        self.app.catalog.catalog_object(self.app.other_folder,
                                        self.app.other_folder.absolute_url(1))
        self.app.oai.harvester.update(True) #Update forced

        #Update the aggregator once again
        self.app.oai_agg.update()

        # Has 2 records in it's contents because the harvester can be updated
        # only after a day
        self.assertEqual(len(self.app.oai_agg.oai_harv.\
                             objectValues([OAIRecord.meta_type])), 2)

        #We need to do an manual update of the harvester
        self.app.oai_agg.oai_harv.update()
        self.assertEqual(len(self.app.oai_agg.oai_harv.\
                             objectValues([OAIRecord.meta_type])), 3)

        self.app.catalog.uncatalog_object(
            self.app.other_folder.absolute_url(1))
        self.app.manage_delObjects(['other_folder'])

        #Updating ZCatalogHarvester
        self.app.oai.harvester.update(True) #Update forced

        #updating OAIHarvester
        self.app.oai_agg.oai_harv.update()
        self.assertEqual(len(self.app.oai_agg.oai_harv.\
                             objectValues([OAIRecord.meta_type])), 2)
Beispiel #8
0
 def installUi(self):
     '''Installs the user interface'''
     # Some useful imports
     from OFS.Folder import manage_addFolder
     from OFS.Image import manage_addImage, manage_addFile
     # Delete the existing folder if it existed
     zopeContent = self.app.objectIds()
     for name in ('ui', self.favIcon):
         if name in zopeContent: self.app.manage_delObjects([name])
     manage_addFolder(self.app, 'ui')
     # Browse the physical ui folders (the Appy one and an app-specific, if
     # the app defines one) and create the corresponding objects in the Zope
     # folder. In the case of files having the same name in both folders,
     # the one from the app-specific folder is chosen.
     j = os.path.join
     uiFolders = [j(j(appy.getPath(), 'gen'), 'ui')]
     for uiFolder in self.config.appConfig.uiFolders:
         if uiFolder.startswith('..'):
             folder = j(os.path.dirname(self.config.diskFolder),uiFolder[3:])
         else:
             folder = j(self.config.diskFolder, uiFolder)
         if os.path.exists(folder):
             uiFolders.insert(0, folder)
     for ui in uiFolders:
         for root, dirs, files in os.walk(ui):
             folderName = root[len(ui):]
             # Get the Zope folder that corresponds to this name
             zopeFolder = self.app.ui
             if folderName:
                 for name in folderName.strip(os.sep).split(os.sep):
                     zopeFolder = zopeFolder._getOb(name)
             # Create sub-folders at this level
             for name in dirs:
                 if not hasattr(zopeFolder.aq_base, name):
                     manage_addFolder(zopeFolder, name)
             # Create files at this level
             for name in files:
                 ext = os.path.splitext(name)[1]
                 if hasattr(zopeFolder.aq_base, name): continue
                 f = file(j(root, name))
                 if name == self.favIcon:
                     if not hasattr(self.app, name):
                         # Copy it at the root. Else, IE won't notice it.
                         manage_addImage(self.app, name, f)
                 elif ext in gen.File.imageExts:
                     manage_addImage(zopeFolder, name, f)
                 else:
                     manage_addFile(zopeFolder, name, f)
                 f.close()
     # Update home and error pages
     from Products.PageTemplates.ZopePageTemplate import \
          manage_addPageTemplate
     if 'index_html' in zopeContent:
         self.app.manage_delObjects(['index_html'])
     manage_addPageTemplate(self.app, 'index_html', '', homePage)
     if 'standard_error_message' in zopeContent:
         self.app.manage_delObjects(['standard_error_message'])
     manage_addPageTemplate(self.app, 'standard_error_message', '',
                            errorPage)
def initPackage(context):
    site = api.portal.get()
    if not 'replication_connections' in site.keys():
        manage_addFolder(
            site,
            id='replication_connections',
            title='Database Connections for Plomino Replication',
        )
Beispiel #10
0
 def _get_slider_images_folder(self):
     layout_tool = self.getLayoutTool()
     # not using get_current_skin to make it work for CHMBE
     skin = layout_tool._getOb(layout_tool.getCurrentSkinId())
     # add images folder if it doesn't exist
     if not skin.hasObject('slider-images'):
         manage_addFolder(skin, 'slider-images')
     return skin._getOb('slider-images')
def manage_addXWFMailingList(self, id, mailto, title='Mailing List',
                             REQUEST=None):
    """ Add an XWFMailingList to a container."""
    ob = XWFMailingList(id, title, mailto)
    self._setObject(id, ob)
    ob = getattr(self, id)
    ob.init_properties()
    manage_addFolder(ob, b'archive', 'mailing list archives')

    if REQUEST is not None:
        return self.manage_main(self, REQUEST)
    def setUp( self ):
        import cStringIO
        import transaction
        from AccessControl import SecurityManager
        from AccessControl.SecurityManagement import newSecurityManager
        from OFS.Application import Application
        from OFS.Folder import manage_addFolder
        from OFS.Image import manage_addFile
        from Testing.makerequest import makerequest
        from ZODB.DB import DB
        from ZODB.DemoStorage import DemoStorage

        s = DemoStorage()
        self.connection = DB(s).open()

        try:
            r = self.connection.root()
            a = Application()
            r['Application'] = a
            self.root = a
            responseOut = self.responseOut = cStringIO.StringIO()
            self.app = makerequest( self.root, stdout=responseOut )
            manage_addFolder( self.app, 'folder1' )
            folder1 = getattr( self.app, 'folder1' )
            setattr(folder1, '+something', 'plus')

            folder1.all_meta_types = \
                                    ({ 'name'        : 'File'
                                     , 'action'      : 'manage_addFile'
                                     , 'permission'  : 'Add images and files'
                                     }
                                    ,
                                    )

            manage_addFile( folder1, 'file'
                          , file='', content_type='text/plain')

            # Hack, we need a _p_mtime for the file, so we make sure that it
            # has one. We use a subtransaction, which means we can rollback
            # later and pretend we didn't touch the ZODB.
            transaction.commit()
        except:
            self.connection.close()
            raise
        transaction.begin()
        self.folder1 = getattr( self.app, 'folder1' )

        self.policy = UnitTestSecurityPolicy()
        self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
        newSecurityManager( None, self._makeUser().__of__( self.root ) )
    def test_category_object(self):
        # Permissions for action category 'object*' should be
        # evaluated in object context.
        manage_addFolder(self.site, 'actions_dummy')
        self.object = self.site.actions_dummy
        self.object.manage_permission('View', [], acquire=0)

        WANTED = {'allowed': False, 'category': 'object'}

        action = {'name': 'foo', 'url': '', 'permissions': ('View',)}
        ec = createExprContext(self.site, self.site, self.object)
        ai = self._makeOne(action, ec)

        self.assertEqual( ai['category'], WANTED['category'] )
        self.assertEqual( ai['allowed'], WANTED['allowed'] )
Beispiel #14
0
def initialize(context):
    """ """
    app = context._ProductContext__app

    context.registerClass(
            CronTool,
            permission=PERMISSION_ADD_CRON_TOOL,
            constructors=CronTool._constructors
    )

    if app._getOb('naaya_admin_tool', None) is None:
        manage_addFolder(app, 'naaya_admin_tool', title='Naaya Admin Tool')
        LOG('NaayaAdminTool', INFO, 'naaya_admin_tool folder created')
    naaya_admin_tool = app._getOb('naaya_admin_tool')

    configure_catalog(app)
    configure_cron(naaya_admin_tool)
Beispiel #15
0
    def installBaseObjects(self):
        '''Creates the tool and the base data folder if they do not exist.'''
        # Create the tool.
        zopeContent = self.app.objectIds()
        from OFS.Folder import manage_addFolder

        if 'config' not in zopeContent:
            toolName = '%sTool' % self.productName
            gutils.createObject(self.app, 'config', toolName, self.productName,
                                wf=False, noSecurity=True)
        # Create the base data folder.
        if 'data' not in zopeContent: manage_addFolder(self.app, 'data')

        # Remove some default objects created by Zope but not useful to Appy
        for name in ('standard_html_footer', 'standard_html_header',\
                     'standard_template.pt'):
            if name in zopeContent: self.app.manage_delObjects([name])
Beispiel #16
0
    def initialize(self):
        """ Adding a catalog with needed indexes and other stuff """
        catalog_id = DEFAULTS["catalog"]
        manage_addZCatalog(self, catalog_id, "Default catalog")
        catalog_ob = self._getOb(catalog_id)

        # Add Lexicon
        elem = []
        wordSplitter = Empty()
        wordSplitter.group = "Locale Aware Word Splitter"
        wordSplitter.name = "Locale Aware Word Splitter"

        caseNormalizer = Empty()
        caseNormalizer.group = "Case Normalizer"
        caseNormalizer.name = "Case Normalizer"

        stopWords = Empty()
        stopWords.group = "Stop Words"
        stopWords.name = "Remove listed and single char words"

        accentRemover = Empty()
        accentRemover.group = "Accent Normalizer"
        accentRemover.name = "Accent Normalizer"

        elem.append(wordSplitter)
        elem.append(caseNormalizer)
        elem.append(stopWords)
        elem.append(accentRemover)

        try:
            catalog_ob.manage_addProduct["ZCTextIndex"].manage_addLexicon("Lexicon", "Default Lexicon", elem)
        except:
            pass

        self.add_indexes(catalog_ob)
        self.add_metadata(catalog_ob)

        # Add Token folder
        manage_addFolder(self, DEFAULTS["tokens_folder"], "Token storage")
        # Add Namespace folder
        manage_addFolder(self, DEFAULTS["namespaces_folder"], "Namespace storage")
        # Add Dublic Core OAINamespace
        manage_addOAINamespace(self._getOb(DEFAULTS["namespaces_folder"]))
    def setUp(self):
        LDAPTest.setUp(self)
        luf = self.folder.acl_users
        luf._implicit_mapping = True

        fakeldap.addTreeItems(sg('groups_base'))
        manage_addFolder(self.folder, 'lustest')
        self.lustest = self.folder.lustest
        manage_addLDAPUserSatellite( self.lustest
                                   , sg('luf')
                                   , sg('title')
                                   , sg('recurse')
                                   )
        self.lus = self.lustest.acl_satellite
        acl = self.folder.acl_users
        for role in ug('user_roles'):
            acl.manage_addGroup(role)
        for group in ug('ldap_groups'):
            acl.manage_addGroup(group)
        acl.manage_addUser(REQUEST=None, kwargs=user)
 def setUp(self):
     self.folder = Folder('folder1')
     manage_addFolder(self.folder, 'folder11')
     manage_addFolder(self.folder, 'folder12')
     manage_addFolder(self.folder, 'folder13')
     self.db = DB(MappingStorage())
     self.connection = self.db.open()
Beispiel #19
0
    def installBaseObjects(self):
        '''Creates the tool and the root data folder if they do not exist.'''
        # Create or update the base folder for storing data
        zopeContent = self.app.objectIds()
        from OFS.Folder import manage_addFolder

        if 'config' not in zopeContent:
            toolName = '%sTool' % self.productName
            createObject(self.app, 'config', toolName, self.productName,
                         wf=False, noSecurity=True)

        if 'data' not in zopeContent:
            manage_addFolder(self.app, 'data')
            data = self.app.data
            tool = self.app.config
            # Manager has been granted Add permissions for all root classes.
            # This may not be desired, so remove this.
            for className in self.config.rootClasses:
                permission = self.getAddPermission(className)
                data.manage_permission(permission, (), acquire=0)
            # All roles defined as creators should be able to create the
            # corresponding root classes in this folder.
            i = -1
            for klass in self.config.appClasses:
                i += 1
                if not klass.__dict__.has_key('root') or \
                   not klass.__dict__['root']:
                    continue # It is not a root class
                className = self.config.appClassNames[i]
                wrapperClass = tool.getAppyClass(className, wrapper=True)
                creators = wrapperClass.getCreators(self.config)
                permission = self.getAddPermission(className)
                updateRolesForPermission(permission, tuple(creators), data)

        # Remove some default objects created by Zope but not useful to Appy
        for name in ('standard_html_footer', 'standard_html_header',\
                     'standard_template.pt'):
            if name in zopeContent: self.app.manage_delObjects([name])
Beispiel #20
0
    def setUp(self):
        import io
        import string
        import transaction
        from OFS.Application import Application
        from OFS.Folder import manage_addFolder
        from OFS.Image import manage_addFile
        from Testing.makerequest import makerequest
        self.responseOut = io.BytesIO()
        self.connection = makeConnection()
        try:
            r = self.connection.root()
            a = Application()
            r['Application'] = a
            self.root = a
            self.app = makerequest(self.root, stdout=self.responseOut)
            try:
                self.app._delObject(TESTFOLDER_NAME)
            except AttributeError:
                pass
            manage_addFolder(self.app, TESTFOLDER_NAME)
            folder = getattr(self.app, TESTFOLDER_NAME)

            data = string.ascii_letters.encode('ascii')
            manage_addFile(
                folder, 'file', file=data, content_type='text/plain')

            self.file = folder.file
            self.data = data

            # Hack, we need a _p_mtime for the file, so we make sure that it
            # has one. We use a subtransaction, which means we can rollback
            # later and pretend we didn't touch the ZODB.
            transaction.commit()
        except Exception:
            self.connection.close()
            raise
    def setUp( self ):

        self.connection = makeConnection()
        try:
            r = self.connection.root()
            a = Application()
            r['Application'] = a
            self.root = a
            responseOut = self.responseOut = cStringIO.StringIO()
            self.app = makerequest( self.root, stdout=responseOut )
            manage_addFolder( self.app, 'folder1' )
            folder1 = getattr( self.app, 'folder1' )

            folder1.all_meta_types = \
                                    ( { 'name'        : 'File'
                                      , 'action'      : 'manage_addFile'
                                      , 'permission'  : 'Add images and files'
                                      }
                                    ,
                                    )

            manage_addFile( folder1, 'file'
                          , file='', content_type='text/plain')

            # Hack, we need a _p_mtime for the file, so we make sure that it
            # has one. We use a subtransaction, which means we can rollback
            # later and pretend we didn't touch the ZODB.
            get_transaction().commit()
        except:
            self.connection.close()
            raise
        get_transaction().begin()
        self.folder1 = getattr( self.app, 'folder1' )

        self.policy = UnitTestSecurityPolicy()
        self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
        newSecurityManager( None, UnitTestUser().__of__( self.root ) )
 def setUp(cls):
     # Apparently, other tests have already registered the
     #   handler below, even twice
     #   Clean up those registrations and
     #   make a single clean registration
     #   remember when we must remove our registration
     regs = [r for r in globalSiteManager.registeredHandlers()
             if r.factory is IPubFailureSubscriber
             ]
     if regs:
         globalSiteManager.unregisterHandler(IPubFailureSubscriber)
     cls._unregister = not regs
     globalSiteManager.registerHandler(IPubFailureSubscriber)
     # Set up our test structure
     #   /
     #     sel_f1/
     #             error_log
     #             sel_f2/
     #                    error_log
     app = Testing.ZopeTestCase.app()
     # first level folder
     manage_addFolder(app, 'sel_f1')
     sel_f1 = app.sel_f1
     # second level folder
     manage_addFolder(sel_f1, 'sel_f2')
     sel_f2 = sel_f1.sel_f2
     # put an error log in each of those folders
     # (used in `test_correct_log_*`)
     for f in (sel_f1, sel_f2):
         manage_addErrorLog(f)
         el = f.error_log
         el._ignored_exceptions = ()  # do not ignore exceptions
     transaction.commit()
     # make `manage_delObjects` temporarily public
     cls._saved_roles = Folder.manage_delObjects__roles__
     Folder.manage_delObjects__roles__ = None  # public
Beispiel #23
0
    def testNextPreviousItems(self):
        container = self.folder[self.folder.invokeFactory("Folder", "case3")]
        for id in range(1, 4):
            container.invokeFactory("Document", "subDoc%d" % id)

        from OFS.Folder import manage_addFolder

        manage_addFolder(container, "notacontentishtype")

        for id in range(5, 6):
            container.invokeFactory("Document", "subDoc%d" % id)

        adapter = INextPreviousProvider(container)
        # text data for next/previous items
        next = adapter.getNextItem(container.subDoc2)
        self.assertEqual(next["id"], "subDoc3")
        self.assertEqual(next["portal_type"], "Document")
        self.assertEqual(next["url"], container.subDoc3.absolute_url())
        previous = adapter.getPreviousItem(container.subDoc2)
        self.assertEqual(previous["id"], "subDoc1")
        self.assertEqual(previous["portal_type"], "Document")
        self.assertEqual(previous["url"], container.subDoc1.absolute_url())

        # #11234 not contentish contents shouldn't be returned
        # as next or previous content
        next = adapter.getNextItem(container.subDoc3)
        self.assertEqual(next["id"], "subDoc5")
        previous = adapter.getPreviousItem(container.subDoc5)
        self.assertEqual(previous["id"], "subDoc3")

        # first item should not have a previous item
        previous = adapter.getPreviousItem(container.subDoc1)
        self.assertEqual(previous, None)
        # last item should not have a next item
        next = adapter.getNextItem(container.subDoc5)
        self.assertEqual(next, None)
 def installUi(self):
     '''Installs the user interface.'''
     # Some useful imports
     from OFS.Folder import manage_addFolder
     from OFS.Image import manage_addImage, manage_addFile
     from Products.PythonScripts.PythonScript import PythonScript
     from Products.PageTemplates.ZopePageTemplate import \
          manage_addPageTemplate
     # Delete the existing folder if it existed.
     zopeContent = self.app.objectIds()
     if 'ui' in zopeContent: self.app.manage_delObjects(['ui'])
     manage_addFolder(self.app, 'ui')
     # Browse the physical ui folders (the Appy one and an app-specific, if
     # the app defines one) and create the corresponding objects in the Zope
     # folder. In the case of files having the same name in both folders,
     # the one from the app-specific folder is chosen.
     j = os.path.join
     uiFolders = [j(j(appy.getPath(), 'gen'), 'ui')]
     appUi = j(self.config.diskFolder, 'ui')
     if os.path.exists(appUi): uiFolders.insert(0, appUi)
     for ui in uiFolders:
         for root, dirs, files in os.walk(ui):
             folderName = root[len(ui):]
             # Get the Zope folder that corresponds to this name
             zopeFolder = self.app.ui
             if folderName:
                 for name in folderName.strip(os.sep).split(os.sep):
                     zopeFolder = zopeFolder._getOb(name)
             # Create sub-folders at this level
             for name in dirs:
                 if not hasattr(zopeFolder.aq_base, name):
                     manage_addFolder(zopeFolder, name)
             # Create files at this level
             for name in files:
                 zopeName, ext = os.path.splitext(name)
                 if ext not in ('.pt', '.py'):
                     # In the ZODB, pages and scripts have their name without
                     # their extension.
                     zopeName = name
                 if hasattr(zopeFolder.aq_base, zopeName): continue
                 f = file(j(root, name))
                 if zopeName == 'favicon.ico':
                     if not hasattr(self.app, zopeName):
                         # Copy it at the root. Else, IE won't notice it.
                         manage_addImage(self.app, zopeName, f)
                 elif ext in gen.File.imageExts:
                     manage_addImage(zopeFolder, zopeName, f)
                 elif ext == '.pt':
                     manage_addPageTemplate(zopeFolder, zopeName, '',
                                            f.read())
                 elif ext == '.py':
                     obj = PythonScript(zopeName)
                     zopeFolder._setObject(zopeName, obj)
                     zopeFolder._getOb(zopeName).write(f.read())
                 else:
                     manage_addFile(zopeFolder, zopeName, f)
                 f.close()
     # Update the home page
     if 'index_html' in zopeContent:
         self.app.manage_delObjects(['index_html'])
     manage_addPageTemplate(self.app, 'index_html', '', homePage)
     # Update the error page
     if 'standard_error_message' in zopeContent:
         self.app.manage_delObjects(['standard_error_message'])
     manage_addPageTemplate(self.app, 'standard_error_message', '',
                            errorPage)
Beispiel #25
0
 def _create_folder(self, app):
     manage_addFolder(app, folder_name)
     self.folder = getattr(app, folder_name)
     self.folder._addRole(user_role)
     self.folder.manage_role(user_role, standard_permissions)
 def _construct(self, context, id):
     """Creates and returns the named folder."""
     manage_addFolder(context, id)
     o = context.restrictedTraverse(id)
     context._p_jar.add(aq_base(o))
     return o