Skip to content. | Skip to navigation

Four Digits | Willemsplein 44, 6811 KD Arnhem, The Netherlands | info@fourdigits.nl
 
Maarten Kling is working as a Senior developer for Four Digits in the Netherlands. Maarten is a Zope developer for seven years and a Plone developer and integrator for four years. Maarten has implemented over a dozen websites, some examples are; Cool Region, NPO and the Royal Dutch Chess Organisation. His specialisation is implementing a website design in Plone based on a Photoshop document and creating viewlets, portlets and content-types.
 

Listing expired Plone content

by Maarten Kling Mar 12, 2010

Using a catalog query to get to expired content. Easy, right?

After searching the whole internet again, it's time to make some documentation for myself and the world :)

My problem: list all news items, including the expired ones.

Warning: Listing expired content may result in showing content that you don't want to.

By default a catalog search does not return expired content. To get expired content you must use: show_all=1 and show_inactive=1

self.context.portal_catalog.queryCatalog(query, show_all=1, show_inactive=1)

To get all the expired items until today, you can use the folowing query:

from DateTime.DateTime import DateTime
now = DateTime()
query['expires'] = {'query': now, 'range': 'min', }
self.context.portal_catalog.queryCatalog(query, show_all=1, show_inactive=1)

If you do not set an expired date on a item, it is at '2449/12/31'. This means that if you want to get all the items (expired as well as not yet expired), you need to search between a date in the past (like 2000/01/01) and a date in the future (like 2500/01/01).

Also you need to use min:max range. Again, using show_all and show_inactive.

query['expires'] = {
    'query': (DateTime('2000/01/01'), DateTime('2500/01/01')),
    'range': 'min:max',
}
self.context.portal_catalog.queryCatalog(query, show_all=1, show_inactive=1)

For more info, take a look at 'Listing the folder items using portal_catalog' in the Plone Developer Manual

Special thanks to Moo--!

 

A quick reminder on logging in Debug mode:

from Products.CMFPlone.utils import log
log('print log information in fg')
 
Made by Four Digits based on Plone.
Made by Four Digits based on Plone.