020238a59e2aa5665f449051f6701887599201fa
[Plinn.git] / skins / custom_generic / RSS.py
1 ##parameters=
2 ##
3 from ZTUtils import Batch
4 from ZTUtils import LazyFilter
5 from Products.CMFCore.utils import getUtilityByInterfaceName
6 from Products.CMFDefault.utils import decode
7
8 stool = getUtilityByInterfaceName('Products.CMFCore.interfaces.ISyndicationTool')
9
10
11 if not stool.isSyndicationAllowed(context):
12 context.REQUEST.RESPONSE.redirect(context.absolute_url() +
13 '/rssDisabled?portal_status_message=Syndication+is+Disabled')
14 return
15
16
17 options = {}
18
19 options['channel_info'] = { 'base': stool.getHTML4UpdateBase(context),
20 'description': context.Description(),
21 'frequency': stool.getUpdateFrequency(context),
22 'period': stool.getUpdatePeriod(context),
23 'title': context.Title(),
24 'url': context.absolute_url() }
25
26 #key, reverse = context.getDefaultSorting()
27 # TODO: have an independant sorting rule for syndication.
28 # for the moment, RSS may always report recent changes.
29 key, reverse = 'modified', True
30 items = stool.getSyndicatableContent(context)
31 items = sequence.sort( items, ((key, 'cmp', reverse and 'desc' or 'asc'),) )
32 items = LazyFilter(items, skip='View')
33 b_size = stool.getMaxItems(context)
34 batch_obj = Batch(items, b_size, 0, orphan=0)
35 items = []
36 for item in batch_obj:
37 items.append( { 'date': item.modified().HTML4(),
38 'description': item.Description(),
39 'listCreators': item.listCreators(),
40 'listSubjects': item.Subject(),
41 'publisher': item.Publisher(),
42 'rights': item.Rights(),
43 'title': item.Title(),
44 'url': item.absolute_url() } )
45 options['listItemInfos'] = tuple(items)
46
47 return context.RSS_template(**decode(options, script))