Package: plone.app.contentlisting
This is valid for Plone 4.1 upwards.Many of the operations for customizations, templates, views and portlets in
Plone are related to lists of content objects. Their sources can be different,
although usually they are some sort of catalog search, the contents of a
particular folder or a list of objects from a relation.To make it simpler to work with these, we have made plone.app.contentlisting,
which ensures that lists of content objects always behave in the same way and
according to predefined interfaces, regardless of what the source of the
objects are. The integrator shouldn’t have to care whether the list of objects
came from the catalog, an ORM or they are the actual objects.Making or getting a contentListingThe typical way to get a contentlisting is to call one of two built-in views:Listing the contents of a Folder or CollectionIn Page templates getting the contents of a folder or the results of a
collection is as simple as this:context/@@contentlistingEvery template-writer’s dream ;)NoteIn previous versions there was only support to list the contents of a
folder withcontext/@@folderListing. There was no collection support.
The@@folderListingview is kept for compatibility, but we encourage
you to use the@@contentlistinginstead.A real example of listing the titles of the content objects of a folder:<ul>
  <li tal:repeat="item context/@@contentlisting" tal:content="item/Title"/>
</ul>The context in which it is called defines which folder is listed or which
collection results are queried.You can also use Python expressions to be able to pass parameters, like which
content type or review state you want to use:<li tal:repeat="item python:context.restrictedTraverse('@@contentlisting')(portal_type='Document')">Batching can be done like this:<ul tal:define="
    Batch python:modules['Products.CMFPlone'].Batch;
    b_size python:int(request.get('b_size', 20));
    b_start python:int(request.get('b_start', 0));
    results python:context.restrictedTraverse('@@contentlisting')(batch=True, b_size=b_size, b_start=b_start);
    batch python:Batch(results, b_size, b_start);">
  <li tal:repeat="item results"
      tal:content="item/Title" />
  <div metal:use-macro="context/batch_macros/macros/navigation" />
</ul>Note that you iterate directly over the results that you get from@@contentlisting.  The definition ofbatchis only used in thebatch_macroscall.In Python a ContentListing of a particular folder’s contents can be fetched
by using:>>> path.to.your.folder.restrictedTraverse('@@contentlisting')()Exactly the same for collections:>>> path.to.your.collection.restrictedTraverse('@@contentlisting')()The contentlisting view called above implements all the logic the old
getFolderContents script in Plone used to do. The old script has been left in
place to not break compatibility for customizations and add-ons that might
depend on its particular return values.Rolling your own with adaptionAt the time of writing, all parts of Plone do not yet return ‘contentlistings’
when asked for lists of content. It was impossible to change this everywhere
without breaking backwards compatibility. Therefore you may have to convert
your sequence of stuff to a contentlisting manually.To do this, you need to import and adapt:>>> from plone.app.contentlisting.interfaces import IContentListing
>>> catalog = getToolByName(self.portal, 'portal_catalog')
>>> results = catalog.searchResults()
>>> contentlist = IContentListing(results)
>>> print(contentlist)
<plone.app.contentlisting.contentlisting.ContentListing object ...>The contentListing, its properties and behaviorsNow, you no longer need to worry whether you have a bunch of catalog brains or
the actual objects (or fake objects for that sake). As long as you have a
contentlisting, you know what you can expect from it. You also know what you
can expect from each item within it - a content listing object.The content listing is a normal iterator that we can loop over and do all sorts
of stuff you normally can do with sequences.contentListingObjects, the items inside the sequenceThecontentListingObjectsare wrapper objects, each representing a content
object in the site. Their intention is to be predictable so you can always call
at least a common base set of methods on the objects listed.You do not have to be aware whether the object originates from a brain, a full
object or something else. If you try to call a method or access an attribute of
the object and the wrapper is not aware of it, it will silently fetch the real
object and delegate the call to it. This means you can treat your objects as
you would any other – even writing to it.Methods of contentlistingObjectsgetId() -Returns the object id in its container for examplemy-example-page.getObject() -Returns the real objectdef getDataOrigin() -The origin of the data for the object.getPath() -Path to the object, relative to the site root for example/artifacts/my-example-pagegetURL()-Full url to the object, including the site root for examplehttp://my.site.com/artifacts/my-example-pageuuid() -Unique content identifier for example an uuid fromplone.uuidThe only real
point of it is to be unique. It can for example look like thisb0e80776-d41d-4f48-bf9e-7cb1aebabad5.getSize() -Size in bytes for example24.review_state() -Workflow review state for examplepublished.ContentTypeClass() -A normalized type name that identifies the object in listings. Used for CSS
styling, for examplecontent-type-page.Title() -Return a single string, the DCMI Title element (resource name).
For exampleMy example page.Description() -Return the DCMI Description element (resource summary). Result is a natural
language description of this object. Description is a plain text string
describing the object. It should not contain HTML or similar.Type() -Return the DCMI Type element (resource type). Result is a human-readable
message id for the resource (typically the Title of its type info object).
For exampleu’Page’from theplonedomain.listCreators() -Return a sequence of DCMI Creator elements (resource authors).
Depending on the implementation, this returns the full name(s) of the
author(s) of the content object or their ids. For exampleJane Smith.Creator() -Return the first DCMI Creator element, or an empty string.
For exampleJane Smith.Subject() -Return a sequence of DCMI Subject elements (resource keywords).
Result is zero or more keywords associated with the content object.
These are the tags in Plone. For example['Ecology', 'Sustainability'].Publisher() -Return the DCMI Publisher element (resource publisher). Result is the full
formal name of the entity or person responsible for publishing the resource.
For examplePlone Foundation.listContributors() -Return a sequence of DCMI Contributor elements (resource collaborators).
Return zero or more collaborators (beyond those returned bylistCreators).Contributors() -Deprecated alias forlistContributors.Date(zone=None) -Return the DCMI Date element (default resource date). Result is a string,
formatted ‘YYYY-MM-DD H24:MN:SS TZ’. The zone keyword is not yet supported
(but is part of the DublinCore interface and has to stay)CreationDate(zone=None) -Return the DCMI Date element (date resource created). Result is a string,
formatted ‘YYYY-MM-DD H24:MN:SS TZ’. The zone keyword is not yet supported
(but is part of the DublinCore interface and has to stay)EffectiveDate(zone=None) -Return the DCMI Date element (date resource becomes effective). Result is a
string, formatted ‘YYYY-MM-DD H24:MN:SS TZ’, or None. The zone keyword is
not yet supported (but is part of the DublinCore interface and has to stay)ExpirationDate(zone=None) -Return the DCMI Date element (date resource expires). Result is a string,
formatted ‘YYYY-MM-DD H24:MN:SS TZ’, or None. The zone keyword is not yet
supported (but is part of the DublinCore interface and has to stay)ModificationDate(zone=None) -DCMI Date element - date resource last modified. Result is a string,
formatted ‘YYYY-MM-DD H24:MN:SS TZ’. The zone keyword is not yet supported
(but is part of the DublinCore interface and has to stay)Format() -Return the DCMI Format element (resource format).
Result is the resource’s MIME type (e.g.text/html,image/png, etc.).Identifier() -Return the DCMI Identifier element (resource ID). Result is a unique ID
(a URL) for the resource.Language() -DCMI Language element (resource language). Result it the RFC language code
(e.g.en-US,pt-BR) for the resource.Rights() -Return the DCMI Rights element (resource copyright). Return a string
describing the intellectual property status, if any, of the resource.isVisibleInNav() -Return whether this object will be visible in a navigation view.MimeTypeIcon():Return mimetype icon from mimetype registry if contenttype isFile else None.Changelog3.0.4 (2023-10-07)Internal:Update configuration files.
[plone devs] (cfffba8c)3.0.3 (2023-04-15)Internal:Drop p.a.contenttypes install dependency, it is actually a soft one only.
This allows to break a cyclic dependency.
[gforcada] (#3764)3.0.2 (2023-04-06)Internal:Update configuration files.
[plone devs] (#47959565)3.0.1 (2022-12-05)Bug fixes:In RealContentListingObject.__getattr__ check attribute existence without acquisition but return the attribute with acquisition in case it is a method that needs acquisition. [gbastien] (#47)3.0.0 (2022-11-30)Bug fixes:Final release.
[gforcada] (#600)3.0.0b1 (2022-08-30)Bug fixes:Build mime-type icon url with the absolute url. Fixes #44
[erral] (#44)3.0.0a1 (2022-05-14)Breaking changes:Drop Python 2 and Plone 5.2, use plone.base.
[jensens] (#43)2.0.7 (2022-03-09)Bug fixes:realobject: Do not throw an AttributeError when accessing attributes which returnNone. (#42)2.0.6 (2022-01-07)Bug fixes:Do not throw an error when the contenttype is not in the mimetypes_registry.
[tschorr] (#41)2.0.5 (2021-11-23)Bug fixes:Adapt the tests for Plone 6 [ale-rt] (#39)2.0.4 (2021-09-15)Bug fixes:Remove cyclic dependency with Products.CMFPlone
[ericof] (#37)2.0.3 (2020-09-26)Bug fixes:Fixed deprecation warning for LazyCat/LazyMap.
[maurits] (#3130)2.0.2 (2020-04-20)Bug fixes:Minor packaging updates. (#1)2.0.1 (2020-03-21)Bug fixes:Minor packaging updates. [various] (#1)Initialize towncrier.
[gforcada] (#2548)2.0.0 (2018-10-30)Breaking changes:Remove Python2.6 support.
[ale-rt]New features:Python 3 support
[hvelarde, gforcada, davisagli]Use human_readable_size from Products.CMFPlone.utils to replace getObjSize
script. #1801
[reinhardt]Bug fixes:In Zope4 brains can not longer acquire the REQUEST.
[pbauer]Fix tests after collective.indexing moved into core.
[pbauer]1.3.1 (2017-08-08)Bug fixes:fixes code conventions
[loechel]Fix Lookup of review_state on objects that do not have an review_state, example related_items that are files could be such.
[loechel]1.3.0 (2017-07-03)New features:provide Mimetype icon path for file types in contentlisting objecthttps://github.com/plone/Products.CMFPlone/issues/1734[fgrcon]1.2.9 (2017-05-06)Bug fixes:Remove hasattr.
[ivanteoh]1.2.8 (2016-11-19)Bug fixes:Remove ZopeTestCase.
[ivanteoh, maurits]1.2.7 (2016-08-19)Bug fixes:MakegetSizework on RealContentListingObject on types w/o any Primaryfield.
[jensens]1.2.6 (2016-07-05)Bug fixes:Added missing implementation for getSize on RealContentListingObject.
Interface was not fulfilled here.
[jensens]1.2.5 (2016-05-12)Fixes:Removed docstrings from some methods to avoid publishing them.  From
Products.PloneHotfix20160419.  [maurits]1.2.4 (2016-02-08)Fixes:Minor cleanup (decorator, utf8 header, …), removed unused imports and
fixed dependencies.
[jensens]1.2.3 (2015-11-25)Fixes:In tests, useselection.anyin querystrings.
Issuehttps://github.com/plone/Products.CMFPlone/issues/1040[maurits]Cleanup and rework: contenttype-icons and showing thumbnails
for images/leadimages in listingshttps://github.com/plone/Products.CMFPlone/issues/1226[fgrcon]1.2.2 (2015-09-20)ids_not_to_list has been removed. Use the exclude from navigation
setting instead.
[jensens]1.2.1 (2015-09-11)Implement cropping for CroppedDescription.
[pbauer]1.2 (2015-07-18)Introduce@@contentlistingview, which is also supports Collections from
plone.app.contenttypes including filtering of results. This gives us a
unified interface for listing content from Folders or Collections.
Deprecate@@folderListing, which is kept for BBB compatibility.
[thet]1.1.3 (2015-05-05)Make isVisibleInNav method read navigation displayed types settings from
plone.app.registry instead of portal properties. This fixeshttps://github.com/plone/Products.CMFPlone/issues/454.
[timo]1.1.2 (2015-05-05)Pep8.
[thet]1.1.1 (2015-03-13)Add remaining, implemented but missing IContentListing interface methods.
[thet]forward getURL’s relative kw for contentlistings (plone4 compat)
[kiorky]1.1.0 (2014-04-16)Use proper styleguide for headings.
[polyester]Move README to /docs folder.
[polyester]Replace deprecated test assert statements.
[tisto]Removing language tests and fixing icon tests to get the correct images.
[bloodbare]Use PLONE_APP_CONTENTTYPES fixture for Plone 5.
[tisto]1.0.5 (2013-08-13)Add missing getDataOrigin method to interfaces.
[timo]1.0.4 (2013-01-01)Nothing changed.1.0.3 (2012-10-29)Whoever heard I liked batching was wrong. The Catalog results are
already batched, so don’t batch them again.
[lentinj]1.0.2 (2012-10-15)Nothing changed.1.0.1 (2012-04-15)Change ContentTypeClass to return contenttype-{portal_type} to match
what the rest of Plone expects. This fixes sprite based icons for
pages/documents.
[gaudenz]1.0 - 2011-07-19RemovedsearchResultsview and related code. Search is handled insideplone.app.search.
[hannosch]RenameduniqueIdentifiermethod touuidfor shorter and more consistent
naming withplone.uuid.
[hannosch]0.1b2 - 2011-04-15Unit tests for appendViewAction, compare against portal_type rather than Type.
[lentinj]Handle RealContentListingObject objects in isVisibleFromNav,
appendViewAction. Remove memoise, isn’t going to cache anything for a useful
amount of time.
[lentinj]0.1b1 - 2011-04-15Add an isVisibleFromNav method, based onhttp://siarp.de/node/201, use
memoise to cache lookup of portal_properties
[lentinj]Add MANIFEST.in.
[WouterVH]0.1a1 - 2011-03-02Initial release