Listing expired Plone content
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')