當前位置: 首頁>>代碼示例>>Python>>正文


Python collection.ICollection類代碼示例

本文整理匯總了Python中plone.app.contenttypes.behaviors.collection.ICollection的典型用法代碼示例。如果您正苦於以下問題:Python ICollection類的具體用法?Python ICollection怎麽用?Python ICollection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ICollection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_respect_navigation_root

    def test_respect_navigation_root(self):
        portal = self.layer["portal"]
        login(portal, "admin")

        # Create two subsites i.e create two folders and mark them with
        # INavigationRoot
        for i in xrange(1, 3):
            folder_id = "folder{}".format(i)
            portal.invokeFactory("Folder", folder_id, title="Folder{}".format(i))
            folder = portal[folder_id]
            alsoProvides(folder, INavigationRoot)
        folders = (portal["folder1"], portal["folder2"])

        # Add a content item to each folder
        for f in folders:
            f_id = f.getId()
            f.invokeFactory("Document", "item_in_{}".format(f_id), title="Item In {}".format(f_id))

        # Add a collection to folder1
        folder1 = folders[0]
        folder1.invokeFactory("Collection", "collection1", title="Collection 1")
        collection1 = folder1["collection1"]
        wrapped = ICollection_behavior(collection1)
        wrapped.query = [{"i": "portal_type", "o": "plone.app.querystring.operation.string.is", "v": "Document"}]

        # Check if only the item inside folder1 is returned, since it's a
        # navigation root.
        items = wrapped.results(batch=False)
        ids = [i.getId() for i in items]
        self.assertListEqual(ids, ["item_in_folder1"])
開發者ID:naro,項目名稱:plone.app.contenttypes,代碼行數:30,代碼來源:test_collection.py

示例2: test_getFoldersAndImages_returning_images

    def test_getFoldersAndImages_returning_images(self):
        portal = self.layer['portal']
        login(portal, 'admin')
        # add a collection, so we can add a query to it
        portal.invokeFactory("Collection",
                             "collection",
                             title="New Collection")

        # add example folder
        portal.invokeFactory("Folder",
                             "folder1",
                             title="Folder1")
        folder = portal['folder1']

        # add example image into this folder
        folder.invokeFactory("Image",
                             "image",
                             title="Image example")

        # add another image into the portal root
        portal.invokeFactory("Image",
                             "image",
                             title="Image example")
        query = [{
            'i': 'Type',
            'o': 'plone.app.querystring.operation.string.is',
            'v': 'Image',
        }]
        collection = portal['collection']
        wrapped = ICollection_behavior(collection)
        wrapped.query = query
        imagecount = wrapped.getFoldersAndImages()['total_number_of_images']
        self.assertEqual(imagecount, 2)
開發者ID:martior,項目名稱:plone.app.contenttypes,代碼行數:33,代碼來源:test_collection.py

示例3: selectedViewFields

 def selectedViewFields(self):
     """Returns a list of all metadata fields from the catalog that were
        selected.
     """
     context = aq_inner(self.context)
     wrapped = ICollection(context)
     return wrapped.selectedViewFields()
開發者ID:UPCnet,項目名稱:ulearn.theme,代碼行數:7,代碼來源:views.py

示例4: test_custom_query

    def test_custom_query(self):
        portal = self.layer["portal"]
        login(portal, "admin")
        query = [{"i": "portal_type", "o": "plone.app.querystring.operation.string.is", "v": ["News Item", "Document"]}]
        portal.invokeFactory("Collection", "collection", title="New Collection", query=query)

        # item 1
        portal.invokeFactory(id="testnews", type_name="News Item")
        item1 = portal.testnews
        item1.reindexObject()

        # item 2
        portal.invokeFactory(id="testdoc", type_name="Document")
        item2 = portal.testdoc
        item2.reindexObject()

        collection = portal["collection"]
        wrapped = ICollection_behavior(collection)

        # Test unmodified query
        results = wrapped.results(batch=False)
        self.assertEqual(len(results), 2)

        # Test with custom query
        results = wrapped.results(batch=False, custom_query={"portal_type": "Document"})
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].id, "testdoc")

        # Test with custom query, which should not find anything
        results = wrapped.results(batch=False, custom_query={"portal_type": "Document", "id": "bla"})
        self.assertEqual(len(results), 0)
開發者ID:naro,項目名稱:plone.app.contenttypes,代碼行數:31,代碼來源:test_collection.py

示例5: test_sorting_1

    def test_sorting_1(self):
        portal = self.layer["portal"]
        login(portal, "admin")
        query = [{"i": "portal_type", "o": "plone.app.querystring.operation.string.is", "v": "News Item"}]
        portal.invokeFactory(
            "Collection", "collection", title="New Collection", query=query, sort_on="created", sort_reversed=True
        )

        now = DateTime()
        # News Item 1
        portal.invokeFactory(id="newsitem1", type_name="News Item")
        item1 = portal.newsitem1
        item1.creation_date = now - 2
        item1.reindexObject()
        # News Item 2
        portal.invokeFactory(id="newsitem2", type_name="News Item")
        item2 = portal.newsitem2
        item2.creation_date = now - 1
        item2.reindexObject()
        # News Item 3
        portal.invokeFactory(id="newsitem3", type_name="News Item")
        item3 = portal.newsitem3
        item3.creation_date = now
        item3.reindexObject()

        collection = portal["collection"]
        wrapped = ICollection_behavior(collection)
        results = wrapped.results(batch=False)
        ritem0 = results[0]
        ritem1 = results[1]
        ritem2 = results[2]

        self.assertTrue(ritem0.CreationDate() > ritem1.CreationDate())
        self.assertTrue(ritem1.CreationDate() > ritem2.CreationDate())
開發者ID:naro,項目名稱:plone.app.contenttypes,代碼行數:34,代碼來源:test_collection.py

示例6: tabular_fields

 def tabular_fields(self):
     """Returns a list of all metadata fields from the catalog that were
        selected.
     """
     context = aq_inner(self.context)
     wrapped = ICollection(context)
     fields = wrapped.selectedViewFields()
     fields = [field[0] for field in fields]
     return fields
開發者ID:Blaastolen,項目名稱:plone.app.contenttypes,代碼行數:9,代碼來源:collection.py

示例7: results

 def results(self, **kwargs):
     """ Helper to get the results from the collection-behavior.
     The template collectionvew.pt calls the standard_view of collections
     as a macro and standard_view uses python:view.results(b_start=b_start)
     to get the reusults. When used as a macro 'view' is this view instead
     of the CollectionView.
     """
     context = aq_inner(self.context)
     wrapped = ICollection(context)
     return wrapped.results(**kwargs)
開發者ID:collective,項目名稱:Solgema.fullcalendar,代碼行數:10,代碼來源:views.py

示例8: migrate_schema_fields

 def migrate_schema_fields(self):
     migrate_richtextfield(self.old, self.new, 'text', 'text')
     wrapped_new = ICollection(self.new)
     # using migrate_simplefield on 'query' returns the ContentListing obj
     wrapped_new.query = self.old.query
     migrate_simplefield(self.old, wrapped_new, 'sort_on', 'sort_on')
     migrate_simplefield(
         self.old, wrapped_new, 'sort_reversed', 'sort_reversed')
     migrate_simplefield(self.old, wrapped_new, 'limit', 'limit')
     migrate_simplefield(
         self.old, wrapped_new, 'customViewFields', 'customViewFields')
開發者ID:Blaastolen,項目名稱:plone.app.contenttypes,代碼行數:11,代碼來源:migration.py

示例9: test_collection_templates

    def test_collection_templates(self):
        browser = self.browser
        portal = self.layer["portal"]
        login(portal, "admin")
        # add an image that will be listed by the collection
        portal.invokeFactory("Image", "image", title="Image example")

        image = self.portal["image"]
        image.image = dummy_image()

        # add a collection, so we can add a query to it
        portal.invokeFactory("Collection", "collection", title="New Collection")
        collection = portal["collection"]
        # Search for images
        query = [{"i": "Type", "o": "plone.app.querystring.operation.string.is", "v": "Image"}]
        collection.text = RichTextValue(u"Lorem collection ipsum", "text/plain", "text/html")

        wrapped = ICollection_behavior(collection)
        # set the query and publish the collection
        wrapped.query = query
        workflow = portal.portal_workflow
        workflow.doActionFor(collection, "publish")
        commit()
        logout()
        # open a browser to see if our image is in the results
        browser.handleErrors = False
        url = collection.absolute_url()
        browser.open(url)
        self.assertTrue("Lorem collection ipsum" in browser.contents)
        self.assertTrue("Image example" in browser.contents)

        # open summary_view template
        browser.open("%s/@@summary_view" % url)
        self.assertTrue("Lorem collection ipsum" in browser.contents)
        self.assertTrue("Image example" in browser.contents)

        # open all_content template
        browser.open("%s/@@all_content" % url)
        self.assertTrue("Lorem collection ipsum" in browser.contents)
        self.assertTrue("Image example" in browser.contents)

        # open tabular_view template
        browser.open("%s/@@tabular_view" % url)
        self.assertTrue("Lorem collection ipsum" in browser.contents)
        self.assertTrue("Image example" in browser.contents)

        # open thumbnail_view template
        browser.open("%s/@@thumbnail_view" % url)
        self.assertTrue("Lorem collection ipsum" in browser.contents)
        self.assertTrue("Image example" in browser.contents)
開發者ID:naro,項目名稱:plone.app.contenttypes,代碼行數:50,代碼來源:test_collection.py

示例10: test_sorting_1

    def test_sorting_1(self):
        portal = self.layer['portal']
        login(portal, 'admin')
        query = [{
            'i': 'portal_type',
            'o': 'plone.app.querystring.operation.string.is',
            'v': 'News Item',
        }]
        portal.invokeFactory("Collection",
                             "collection",
                             title="New Collection",
                             query=query,
                             sort_on='created',
                             sort_reversed=True,
                             )

        now = DateTime()
        # News Item 1
        portal.invokeFactory(id='newsitem1',
                             type_name='News Item')
        item1 = portal.newsitem1
        item1.creation_date = now - 2
        item1.reindexObject()
        # News Item 2
        portal.invokeFactory(id='newsitem2',
                             type_name='News Item')
        item2 = portal.newsitem2
        item2.creation_date = now - 1
        item2.reindexObject()
        # News Item 3
        portal.invokeFactory(id='newsitem3',
                             type_name='News Item')
        item3 = portal.newsitem3
        item3.creation_date = now
        item3.reindexObject()

        collection = portal['collection']
        wrapped = ICollection_behavior(collection)
        results = wrapped.results(batch=False)
        ritem0 = results[0]
        ritem1 = results[1]
        ritem2 = results[2]

        self.assertTrue(ritem0.CreationDate() > ritem1.CreationDate())
        self.assertTrue(ritem1.CreationDate() > ritem2.CreationDate())
開發者ID:martior,項目名稱:plone.app.contenttypes,代碼行數:45,代碼來源:test_collection.py

示例11: test_custom_query

    def test_custom_query(self):
        portal = self.layer['portal']
        login(portal, 'admin')
        query = [{
            'i': 'portal_type',
            'o': 'plone.app.querystring.operation.string.is',
            'v': ['News Item', 'Document'],
        }]
        portal.invokeFactory("Collection",
                             "collection",
                             title="New Collection",
                             query=query,
                             )

        # item 1
        portal.invokeFactory(id='testnews',
                             type_name='News Item')
        item1 = portal.testnews
        item1.reindexObject()

        # item 2
        portal.invokeFactory(id="testdoc",
                             type_name='Document')
        item2 = portal.testdoc
        item2.reindexObject()

        collection = portal['collection']
        wrapped = ICollection_behavior(collection)

        # Test unmodified query
        results = wrapped.results(batch=False)
        self.assertEqual(len(results), 2)

        # Test with custom query
        results = wrapped.results(batch=False,
                                  custom_query={'portal_type': 'Document'})
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].id, 'testdoc')

        # Test with custom query, which should not find anything
        results = wrapped.results(batch=False,
                                  custom_query={'portal_type': 'Document',
                                                'id': 'bla'})
        self.assertEqual(len(results), 0)
開發者ID:fgrcon,項目名稱:plone.app.contenttypes,代碼行數:44,代碼來源:test_collection.py

示例12: __call__

    def __call__(self):
#         datev = self.layout
        context = self.context
        linkquery = {u'i': u'portal_type', u'o': u'plone.app.querystring.operation.selection.any', u'v': [u'Link', u'Document']}
        from plone.app.contenttypes.behaviors.collection import ICollection as ICollection_behavior
        query = ICollection_behavior(context).query
#         import pdb
#         pdb.set_trace()
        for qr in query:
            if qr['i'] == 'portal_type':
                break
        if bool(qr):
            query.remove(qr)
            query.append(linkquery)
            
        ICollection_behavior(context).query = query
             


        return "link type has been added to  '%s' successfully ." % (context.Title()) 
開發者ID:adam139,項目名稱:xtshzz.policy,代碼行數:20,代碼來源:manage_tools.py

示例13: test_getFoldersAndImages_returning_images

    def test_getFoldersAndImages_returning_images(self):
        portal = self.layer["portal"]
        login(portal, "admin")
        # add a collection, so we can add a query to it
        portal.invokeFactory("Collection", "collection", title="New Collection")

        # add example folder
        portal.invokeFactory("Folder", "folder1", title="Folder1")
        folder = portal["folder1"]

        # add example image into this folder
        folder.invokeFactory("Image", "image", title="Image example")

        # add another image into the portal root
        portal.invokeFactory("Image", "image", title="Image example")
        query = [{"i": "Type", "o": "plone.app.querystring.operation.string.is", "v": "Image"}]
        collection = portal["collection"]
        wrapped = ICollection_behavior(collection)
        wrapped.query = query
        imagecount = wrapped.getFoldersAndImages()["total_number_of_images"]
        self.assertEqual(imagecount, 2)
開發者ID:naro,項目名稱:plone.app.contenttypes,代碼行數:21,代碼來源:test_collection.py

示例14: test_respect_navigation_root

    def test_respect_navigation_root(self):
        portal = self.layer['portal']
        login(portal, 'admin')

        # Create two subsites i.e create two folders and mark them with
        # INavigationRoot
        for i in xrange(1, 3):
            folder_id = 'folder{}'.format(i)
            portal.invokeFactory('Folder',
                                 folder_id,
                                 title='Folder{}'.format(i))
            folder = portal[folder_id]
            alsoProvides(folder, INavigationRoot)
        folders = (portal['folder1'], portal['folder2'])

        # Add a content item to each folder
        for f in folders:
            f_id = f.getId()
            f.invokeFactory('Document',
                            'item_in_{}'.format(f_id),
                            title='Item In {}'.format(f_id))

        # Add a collection to folder1
        folder1 = folders[0]
        folder1.invokeFactory('Collection',
                              'collection1',
                              title='Collection 1')
        collection1 = folder1['collection1']
        wrapped = ICollection_behavior(collection1)
        wrapped.query = [{
            'i': 'portal_type',
            'o': 'plone.app.querystring.operation.string.is',
            'v': 'Document',
        }]

        # Check if only the item inside folder1 is returned, since it's a
        # navigation root.
        items = wrapped.results(batch=False)
        ids = [i.getId() for i in items]
        self.assertListEqual(ids, ['item_in_folder1'])
開發者ID:martior,項目名稱:plone.app.contenttypes,代碼行數:40,代碼來源:test_collection.py

示例15: test_getFoldersAndImages

    def test_getFoldersAndImages(self):
        portal = self.layer['portal']
        login(portal, 'admin')
        # add a collection, so we can add a query to it
        portal.invokeFactory("Collection",
                             "collection",
                             title="New Collection")

        # add example folder and a subfolder to it, both with same id
        portal.invokeFactory("Folder",
                             "folder1",
                             title="Folder1")
        folder = portal['folder1']

        folder.invokeFactory("Folder",
                             "folder1",
                             title="Folder1")
        subfolder = folder['folder1']
        # add example image into folder and its subfolder
        folder.invokeFactory("Image",
                             "image",
                             title="Image example")

        subfolder.invokeFactory("Image",
                                "another_image",
                                title="Image example")
        query = [{
            'i': 'Type',
            'o': 'plone.app.querystring.operation.string.is',
            'v': 'Folder',
        }]
        collection = portal['collection']
        wrapped = ICollection_behavior(collection)
        wrapped.query = query
        imagecount = wrapped.getFoldersAndImages()['total_number_of_images']
        # The current implementation for getFoldersAndImages will return
        # another_image under subfolder and also under folder
        self.assertEqual(imagecount, 3)
開發者ID:martior,項目名稱:plone.app.contenttypes,代碼行數:38,代碼來源:test_collection.py


注:本文中的plone.app.contenttypes.behaviors.collection.ICollection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。