当前位置: 首页>>代码示例>>Python>>正文


Python ICollection.results方法代码示例

本文整理汇总了Python中plone.app.contenttypes.behaviors.collection.ICollection.results方法的典型用法代码示例。如果您正苦于以下问题:Python ICollection.results方法的具体用法?Python ICollection.results怎么用?Python ICollection.results使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plone.app.contenttypes.behaviors.collection.ICollection的用法示例。


在下文中一共展示了ICollection.results方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_custom_query

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
    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,代码行数:33,代码来源:test_collection.py

示例2: test_respect_navigation_root

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
    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,代码行数:32,代码来源:test_collection.py

示例3: test_sorting_1

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
    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,代码行数:36,代码来源:test_collection.py

示例4: test_custom_query

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
    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,代码行数:46,代码来源:test_collection.py

示例5: results

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
 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,代码行数:12,代码来源:views.py

示例6: test_sorting_1

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
    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,代码行数:47,代码来源:test_collection.py

示例7: test_respect_navigation_root

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
    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,代码行数:42,代码来源:test_collection.py

示例8: SummaryViewNews

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
class SummaryViewNews(FolderView):

    def __init__(self, *args, **kwargs):
        super(SummaryViewNews, self).__init__(*args, **kwargs)
        context = aq_inner(self.context)
        self.collection_behavior = ICollection(context)
        self.b_size = self.collection_behavior.item_count

    def results(self, **kwargs):
        """Return a content listing based result set with results from the
        collection query.

        :param **kwargs: Any keyword argument, which can be used for catalog
                         queries.
        :type  **kwargs: keyword argument

        :returns: plone.app.contentlisting based result set.
        :rtype: ``plone.app.contentlisting.interfaces.IContentListing`` based
                sequence.
        """
        # Extra filter
        contentFilter = self.request.get('contentFilter', {})
        contentFilter.update(kwargs.get('contentFilter', {}))
        kwargs.setdefault('custom_query', contentFilter)
        kwargs.setdefault('batch', True)
        kwargs.setdefault('b_size', self.b_size)
        kwargs.setdefault('b_start', self.b_start)

        results = self.collection_behavior.results(**kwargs)
        return results

    def batch(self):
        # collection is already batched.
        return self.results()

    def getFoldersAndImages(self, **kwargs):
        context = aq_inner(self.context)
        wrapped = ICollection(context)
        return wrapped.getFoldersAndImages(**kwargs)

    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()

    def abrevia(self, summary, sumlenght):
        """ Retalla contingut de cadenes
        """
        bb = ''

        if sumlenght < len(summary):
            bb = summary[:sumlenght]

            lastspace = bb.rfind(' ')
            cutter = lastspace
            precut = bb[0:cutter]

            if precut.count('<b>') > precut.count('</b>'):
                cutter = summary.find('</b>', lastspace) + 4
            elif precut.count('<strong>') > precut.count('</strong>'):
                cutter = summary.find('</strong>', lastspace) + 9
            bb = summary[0:cutter]

            if bb.count('<p') > precut.count('</p'):
                bb += '...</p>'
            else:
                bb = bb + '...'
        else:
            bb = summary

        return bb

    def effectiveDate(self, item):
        if item.EffectiveDate() == 'None':
            date = str(item.creation_date.day()) + '/' + str(item.creation_date.month()) + '/' + str(item.creation_date.year()),
        else:
            date = str(item.effective_date.day()) + '/' + str(item.effective_date.month()) + '/' + str(item.effective_date.year()),
        return date[0]

    def abreviaText(self, item):
        text = self.abrevia(item.text.raw, 180)
        return text
开发者ID:UPCnet,项目名称:ulearn.theme,代码行数:87,代码来源:views.py

示例9: CollectionView

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
class CollectionView(FolderView):

    def __init__(self, *args, **kwargs):
        super(CollectionView, self).__init__(*args, **kwargs)
        context = aq_inner(self.context)
        self.collection_behavior = ICollection(context)
        self.b_size = self.collection_behavior.item_count

    def results(self, **kwargs):
        """Return a content listing based result set with results from the
        collection query.

        :param **kwargs: Any keyword argument, which can be used for catalog
                         queries.
        :type  **kwargs: keyword argument

        :returns: plone.app.contentlisting based result set.
        :rtype: ``plone.app.contentlisting.interfaces.IContentListing`` based
                sequence.
        """
        # Extra filter
        contentFilter = self.request.get('contentFilter', {})
        contentFilter.update(kwargs.get('contentFilter', {}))
        kwargs.setdefault('custom_query', contentFilter)
        kwargs.setdefault('batch', True)
        kwargs.setdefault('b_size', self.b_size)
        kwargs.setdefault('b_start', self.b_start)

        results = self.collection_behavior.results(**kwargs)
        return results

    def batch(self):
        # collection is already batched.
        return self.results()

    @property
    @memoize
    def _album_results(self):
        """Get results to display an album with subalbums.
        """
        results = self.results()
        images = []
        folders = []
        for it in results:
            # TODO: potentially expensive!
            ob = it.getObject()
            if IImage.providedBy(ob):
                images.append(it)
            elif IFolder.providedBy(ob):
                folders.append(it)
        return {'images': images, 'folders': folders}

    @property
    def album_images(self):
        """Get all images within this collection.
        """
        return self._album_results['images']

    @property
    def album_folders(self):
        """Get all folders within this collection.
        """
        return self._album_results['folders']

    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

    def no_items_message(self):
        return _(
            'description_no_results_found',
            default=u"No results were found."
        )
开发者ID:Blaastolen,项目名称:plone.app.contenttypes,代码行数:81,代码来源:collection.py

示例10: results

# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import results [as 别名]
 def results(self, **kwargs):
     context = aq_inner(self.context)
     wrapped = ICollection(context)
     return wrapped.results(**kwargs)
开发者ID:reinhardt,项目名称:plone.app.contenttypes,代码行数:6,代码来源:collection.py


注:本文中的plone.app.contenttypes.behaviors.collection.ICollection.results方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。