本文整理汇总了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"])
示例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)
示例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()
示例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)
示例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())
示例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
示例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)
示例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')
示例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)
示例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())
示例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)
示例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())
示例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)
示例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'])
示例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)