products/CPSRSS

view RSSChannelContainer.py @ 290:ae269cbbed26

hgbundler init new CHANGES file
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Wed, 23 Nov 2011 19:59:09 +0100
parents 8b941a0115c5
children
line source
1 # (C) Copyright 2003 Nuxeo SARL <http://nuxeo.com>
2 # 2010 Georges Racinet <georges@racinet.fr>
3 # Authors: Emmanuel Pietriga (ep@nuxeo.com)
4 # Georges Racinet <georges@racinet.fr>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as published
8 # by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 # 02111-1307, USA.
19 #
20 """The RSS tool manages RSS channels and refreshes them.
21 """
23 from zLOG import LOG, DEBUG
24 from Globals import InitializeClass, DTMLFile
25 from AccessControl import ClassSecurityInfo
26 from OFS.Folder import Folder
28 from Products.CMFCore.permissions import View, ManagePortal
29 from Products.CMFCore.utils import UniqueObject
31 from RSSChannel import addRSSChannel, RSSChannel_meta_type
33 from zope.interface import implements
35 from Products.CPSRSS.interfaces import IRSSTool
36 from Products.CPSRSS.interfaces import IRSSChannelContainer
38 class RSSChannelContainer(Folder):
39 """RSS tool, a container for RSS channels that can refresh them."""
41 implements(IRSSChannelContainer)
43 meta_type = 'RSS Channel Container'
45 security = ClassSecurityInfo()
46 security.declareObjectProtected(View)
48 def __init__(self, zid):
49 self._setId(zid)
51 #
52 # API
53 #
55 security.declareProtected(ManagePortal, 'refresh')
56 def refresh(self, REQUEST=None):
57 """Refresh all the channels from their source."""
58 for ob in self.objectValues(RSSChannel_meta_type):
59 ob.refresh()
60 if REQUEST:
61 REQUEST.RESPONSE.redirect(
62 '%s/manage_main?manage_tabs_message=Refreshed.'
63 % self.absolute_url())
65 #
66 # CMF views
67 #
68 def __call__(self, REQUEST=None, **kw):
69 """Default view."""
70 return self.view(REQUEST=REQUEST, **kw)
72 index_html = None # This special value informs ZPublisher to use __call__
74 security.declareProtected(View, 'view')
75 def view(self, REQUEST=None, **kw):
76 """Default view."""
77 # FIXME rsstool_view doesn't exist
78 return self.rsstool_view(REQUEST=REQUEST, **kw)
80 #
81 # ZMI
82 #
83 _properties = (
84 {'id': 'refresh_delay', 'type': 'int', 'mode': 'w',
85 'label': 'Refresh Delay'},
86 {'id': 'lazy_refresh', 'type': 'boolean', 'mode': 'w',
87 'label': 'Lazy Refresh'},
88 )
90 title = ''
91 refresh_delay = 1200 # 20 minutes
92 lazy_refresh = 1
94 all_meta_types = (
95 {'name': RSSChannel_meta_type,
96 'action': 'manage_addRSSChannelForm',
97 'permission': ManagePortal,
98 },
99 )
101 manage_addRSSChannelForm = DTMLFile('zmi/addRSSChannelForm', globals())
103 security.declareProtected(ManagePortal, 'manage_addRSSChannel')
104 def manage_addRSSChannel(self, id, channel_url, REQUEST=None, **kw):
105 """Add a RSS Channel from the ZMI."""
106 if REQUEST:
107 kw.update(REQUEST.form)
108 del kw['id']
109 container = self
110 addRSSChannel(container, id, channel_url)
111 if REQUEST:
112 REQUEST.RESPONSE.redirect('%s/%s/manage_workspace'
113 % (container.absolute_url(), id))
115 manage_options = (Folder.manage_options[:1] + # contents
116 ({'label': 'Refresh', 'action': 'refreshForm'},) +
117 Folder.manage_options[1:])
119 refreshForm = DTMLFile('zmi/refreshForm', globals())
122 InitializeClass(RSSChannelContainer)
125 def addRSSChannelContainer(folder, cid='.cps_rss'):
126 """Add a channel container in folder and return it.
128 This does not redirect to a ZMI URL like addRSSChannel does in case a
129 request would be provided, because ZMI would not the only UI.
130 """
131 folder._setObject(cid, RSSChannelContainer(cid))
132 return folder[cid]