products/CPSRSS

changeset 217:e45ebb5d4820 authforward

needed upgrade step
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Thu, 15 Jul 2010 14:15:21 +0200
parents 30f6d0876296
children a94ff92c1518
files RSSChannel.py configure.zcml upgrade.py
diffstat 3 files changed, 53 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/RSSChannel.py
     1.2 +++ b/RSSChannel.py
     1.3 @@ -149,16 +149,8 @@
     1.4          self.new_window = new_window
     1.5          self.nbMaxItems = nbMaxItems
     1.6          self.html_feed = html_feed
     1.7 -        # user-dependent caches (user_id -> data)
     1.8 -        # in case this channel is user-independent, the None key
     1.9 -        # is used for code homogeneity
    1.10 -        self._data = {}
    1.11  
    1.12 -        self._refresh_time = {} # (user_id -> time), same convention
    1.13 -        # user_id (or None) -> dict for etag and modified)
    1.14 -        # GR this is kept separate from _data in order to minimize code
    1.15 -        # to be updated and regression risks.
    1.16 -        self.http_caching_headers = {}
    1.17 +        self.initCaches()
    1.18  
    1.19      #
    1.20      # API
    1.21 @@ -196,6 +188,19 @@
    1.22                  data.update({'lines': lines[:maxItems]})
    1.23          return data
    1.24  
    1.25 +    security.declareProtected(ManagePortal, 'initCaches')
    1.26 +    def initCaches(self):
    1.27 +        # user-dependent caches (user_id -> data)
    1.28 +        # in case this channel is user-independent, the None key
    1.29 +        # is used for code homogeneity
    1.30 +        self._data = {}
    1.31 +
    1.32 +        self._refresh_time = {} # (user_id -> time), same convention
    1.33 +        # user_id (or None) -> dict for etag and modified)
    1.34 +        # GR this is kept separate from _data in order to minimize code
    1.35 +        # to be updated and regression risks.
    1.36 +        self.http_caching_headers = {}
    1.37 +
    1.38      #
    1.39      # internal
    1.40      #
     2.1 --- a/configure.zcml
     2.2 +++ b/configure.zcml
     2.3 @@ -1,6 +1,8 @@
     2.4  <configure
     2.5      xmlns="http://namespaces.zope.org/zope"
     2.6 -    xmlns:five="http://namespaces.zope.org/five">
     2.7 +    xmlns:five="http://namespaces.zope.org/five"
     2.8 +    xmlns:cps="http://namespaces.nuxeo.org/cps">
     2.9 +
    2.10  
    2.11    <adapter
    2.12        factory=".exportimport.RSSToolXMLAdapter"
    2.13 @@ -23,4 +25,10 @@
    2.14        global="False"
    2.15        />
    2.16  
    2.17 +  <cps:upgradeStep
    2.18 +      title="Upgrade channels for user-dependent caches"
    2.19 +      source="3.4.6" destination="3.5.1"
    2.20 +      handler=".upgrade.upgrade_user_cache"
    2.21 +      />
    2.22 +
    2.23  </configure>
     3.1 new file mode 100644
     3.2 --- /dev/null
     3.3 +++ b/upgrade.py
     3.4 @@ -0,0 +1,30 @@
     3.5 +# Copyright 2005-2007 Nuxeo SAS <http://nuxeo.com>
     3.6 +# Author: Julien Anguenot <ja@nuxeo.com>
     3.7 +#
     3.8 +# This program is free software; you can redistribute it and/or modify
     3.9 +# it under the terms of the GNU General Public License version 2 as published
    3.10 +# by the Free Software Foundation.
    3.11 +#
    3.12 +# This program is distributed in the hope that it will be useful,
    3.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 +# GNU General Public License for more details.
    3.16 +#
    3.17 +# You should have received a copy of the GNU General Public License
    3.18 +# along with this program; if not, write to the Free Software
    3.19 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    3.20 +# 02111-1307, USA.
    3.21 +#
    3.22 +# $Id$
    3.23 +
    3.24 +import logging
    3.25 +from RSSChannel import RSSChannel_meta_type
    3.26 +
    3.27 +def upgrade_user_cache(portal):
    3.28 +    """Prepare existing channels for the user-dependent caches."""
    3.29 +
    3.30 +    rss_tool = portal.portal_rss
    3.31 +    for chan in rss_tool.objectValues(['RSS Channel']):
    3.32 +        chan.initCaches()
    3.33 +        # some attributes were persistent, even though the new ones aren't
    3.34 +        chan._p_changed = 1