本文整理汇总了Python中plone.app.contenttypes.behaviors.collection.ICollection.query方法的典型用法代码示例。如果您正苦于以下问题:Python ICollection.query方法的具体用法?Python ICollection.query怎么用?Python ICollection.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.app.contenttypes.behaviors.collection.ICollection
的用法示例。
在下文中一共展示了ICollection.query方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_respect_navigation_root
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [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"])
示例2: test_getFoldersAndImages_returning_images
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [as 别名]
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: migrate_schema_fields
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [as 别名]
def migrate_schema_fields(self):
# migrate the richtext
super(CollectionMigrator, self).migrate_schema_fields()
# migrate the rest of the schema into the behavior
wrapped = ICollection(self.new)
wrapped.query = self.old.query
wrapped.sort_on = self.old.sort_on
wrapped.sort_reversed = self.old.sort_reversed
wrapped.limit = self.old.limit
wrapped.customViewFields = self.old.customViewFields
示例4: migrate_schema_fields
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [as 别名]
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')
示例5: test_collection_templates
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [as 别名]
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)
示例6: migrate_criteria
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [as 别名]
def migrate_criteria(self):
"""Migrate old style to new style criteria.
Plus handling for some special fields.
"""
# The old Topic has boolean limitNumber and integer itemCount,
# where the new Collection only has limit.
adapted = ICollection(self.new)
if self.old.getLimitNumber():
adapted.limit = self.old.getItemCount()
adapted.customViewFields = self.old.getCustomViewFields()
# Get the old data stored by the beforeChange_criteria method.
if self._collection_sort_reversed is not None:
adapted.sort_reversed = self._collection_sort_reversed
if self._collection_sort_on is not None:
adapted.sort_on = self._collection_sort_on
if self._collection_query is not None:
adapted.query = self._collection_query
示例7: test_getFoldersAndImages_returning_images
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [as 别名]
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)
示例8: test_respect_navigation_root
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [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'])
示例9: test_getFoldersAndImages
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [as 别名]
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)
示例10: test_getFoldersAndImages
# 需要导入模块: from plone.app.contenttypes.behaviors.collection import ICollection [as 别名]
# 或者: from plone.app.contenttypes.behaviors.collection.ICollection import query [as 别名]
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)