products/CPSRSS

changeset 244:350fa123d006

Exposed refresh() in view
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Mon, 06 Dec 2010 04:18:50 +0100
parents 56a93ccb2b27
children f8a474119003
files browser/channels.py browser/configure.zcml browser/manage_channels.pt tests/test_views.py
diffstat 4 files changed, 42 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/browser/channels.py
     1.2 +++ b/browser/channels.py
     1.3 @@ -26,6 +26,7 @@
     1.4  
     1.5  from Products.CPSRSS.interfaces import IRSSChannelContainer
     1.6  
     1.7 +
     1.8  class ManageChannels(AqSafeBrowserView):
     1.9  
    1.10      def __init__(self, *args, **kwargs):
    1.11 @@ -57,6 +58,16 @@
    1.12              return ()
    1.13          return cont.objectValues([RSSChannel.meta_type])
    1.14  
    1.15 +    def redirectManageChannels(self):
    1.16 +        self.request.RESPONSE.redirect('/'.join((
    1.17 +                self.context.absolute_url_path(), 'manage_channels.html')))
    1.18 +
    1.19 +    def refresh(self):
    1.20 +        cont = self.aqSafeGet('container')
    1.21 +        if cont is not None:
    1.22 +            cont.refresh()
    1.23 +        self.redirectManageChannels()
    1.24 +
    1.25      def addChannel(self, url=None):
    1.26          """Create a channel from explicit url or from request form.
    1.27  
    1.28 @@ -81,5 +92,4 @@
    1.29          channel.manage_changeProperties(title=title, description=description)
    1.30  
    1.31          cont._setObject(cid, channel)
    1.32 -        self.request.RESPONSE.redirect('/'.join((
    1.33 -                self.context.absolute_url_path(), 'manage_channels.html')))
    1.34 +        self.redirectManageChannels()
     2.1 --- a/browser/configure.zcml
     2.2 +++ b/browser/configure.zcml
     2.3 @@ -18,6 +18,14 @@
     2.4      attribute="addChannel"
     2.5      />
     2.6  
     2.7 +  <browser:page
     2.8 +    for="Products.CPSCore.interfaces.ICPSProxy"
     2.9 +    name="refresh_channels"
    2.10 +    permission="cps.rss.ManageChannels"
    2.11 +    class=".browser.channels.ManageChannels"
    2.12 +    attribute="refresh"
    2.13 +    />
    2.14 +
    2.15    <!--browser:page
    2.16      for="Products.CPSRSS.interfaces.IRSSChannel"
    2.17      name="edit.html"
     3.1 --- a/browser/manage_channels.pt
     3.2 +++ b/browser/manage_channels.pt
     3.3 @@ -39,6 +39,16 @@
     3.4        </label>
     3.5       </form>
     3.6     </p>
     3.7 +
     3.8 +   <h2 i18n:translate="manage_rss_channels_refresh">
     3.9 +    Mettre &agrave; jour tous les flux
    3.10 +   </h2>
    3.11 +   <p>
    3.12 +    <form action="refresh_channels" method="post">
    3.13 +      <input type="submit" value="button_ok" name="add" class="standalone"
    3.14 +             i18n:attributes="value" />
    3.15 +     </form>
    3.16 +   </p>
    3.17    </metal:main>
    3.18  
    3.19   </body>
     4.1 --- a/tests/test_views.py
     4.2 +++ b/tests/test_views.py
     4.3 @@ -75,7 +75,6 @@
     4.4                             dict(id='cps-cms-ticket-query',
     4.5                                  title='CPS CMS: Ticket Query')))
     4.6  
     4.7 -
     4.8      def test_addChannel_form_no_cont(self):
     4.9          # test adding a channel while there's no container yet, from form
    4.10          view = self.makeView()
    4.11 @@ -85,6 +84,18 @@
    4.12          self.assertEquals(self.extractChannels(view),
    4.13                            (dict(id='zope-org', title='Zope.org'),))
    4.14  
    4.15 +    def test_refresh(self):
    4.16 +        view = self.makeView()
    4.17 +        view.addChannel(url=get_feed_url('zope.rss'))
    4.18 +
    4.19 +        # low level url change
    4.20 +        channel = view.channels()[0]
    4.21 +        channel.channel_url = get_feed_url('trac_cps.rss')
    4.22 +        # before refresh
    4.23 +        self.assertEquals(channel.title, 'Zope.org')
    4.24 +        # after
    4.25 +        view.refresh()
    4.26 +        self.assertEquals(channel.title, 'CPS CMS: Ticket Query')
    4.27  
    4.28  def test_suite():
    4.29      return unittest.makeSuite(ManageChannelsTestCase)