[Zope3-checkins] SVN: Zope3/trunk/ Activated Caches again by including a slug in package-includes.

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Jul 8 18:23:56 EDT 2004


Log message for revision 26245:
Activated Caches again by including a slug in package-includes.

Got rid of the CacheName field and replaced it by a 'Cache Names' 
vocabulary and Choice field.

Gave main config file an i18n domain.

Implemented current_cache_url() method for ICacheable view.



-=-
Added: Zope3/trunk/package-includes/cache-configure.zcml
===================================================================
--- Zope3/trunk/package-includes/cache-configure.zcml	2004-07-08 22:20:19 UTC (rev 26244)
+++ Zope3/trunk/package-includes/cache-configure.zcml	2004-07-08 22:23:56 UTC (rev 26245)
@@ -0,0 +1 @@
+<include package="zope.app.cache"/>

Modified: Zope3/trunk/src/zope/app/cache/browser/cacheable.py
===================================================================
--- Zope3/trunk/src/zope/app/cache/browser/cacheable.py	2004-07-08 22:20:19 UTC (rev 26244)
+++ Zope3/trunk/src/zope/app/cache/browser/cacheable.py	2004-07-08 22:23:56 UTC (rev 26245)
@@ -42,10 +42,14 @@
 
     def current_cache_url(self):
         "Returns the current cache provider's URL."
-        # XXX: it would be *really* useful to the user to be able to jump to
-        # the cache component and see the stats etc. directly from the
-        # cacheable view.  All this needs is to find out the URL somehow.
-        return None
+        cache = getCacheForObject(self.context)
+        absolute_url = zapi.getView(cache, 'absolute_url', self.request)
+        try:
+            return absolute_url()
+        except TypeError:
+            # In case the cache object is a global one and does not have a
+            # location, then we just return None. 
+            return None
 
     def invalidate(self):
         "Invalidate the current cached value."

Modified: Zope3/trunk/src/zope/app/cache/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/cache/configure.zcml	2004-07-08 22:20:19 UTC (rev 26244)
+++ Zope3/trunk/src/zope/app/cache/configure.zcml	2004-07-08 22:23:56 UTC (rev 26245)
@@ -1,4 +1,6 @@
-<configure xmlns="http://namespaces.zope.org/zope">
+<configure 
+    xmlns="http://namespaces.zope.org/zope"
+    i18n_domain="zope">
 
   <adapter 
       for="zope.app.annotation.interfaces.IAnnotatable"
@@ -29,7 +31,13 @@
         />
   </content>
 
+  <vocabulary
+      name="Cache Names"
+      factory="zope.app.utility.vocabulary.UtilityVocabulary"
+      interface="zope.app.cache.interfaces.ICache"
+      nameOnly="True" />
 
+
   <!-- Include browser package -->
 
   <include package=".browser" />

Modified: Zope3/trunk/src/zope/app/cache/interfaces/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/cache/interfaces/__init__.py	2004-07-08 22:20:19 UTC (rev 26244)
+++ Zope3/trunk/src/zope/app/cache/interfaces/__init__.py	2004-07-08 22:23:56 UTC (rev 26245)
@@ -15,31 +15,17 @@
 
 $Id$
 """
-from zope.component.exceptions import ComponentLookupError  
 from zope.interface import Interface
-from zope.schema import TextLine
+from zope.schema import Choice
 
-from zope.app import zapi
-
-class CacheName(TextLine):
-    """Cache Name"""
-
-    def __allowed(self):
-        """Note that this method works only if the Field is context wrapped.
-        """
-        names = [name for name, util in zapi.getUtilitiesFor(ICache)]
-        return names + ['']
-
-    allowed_values = property(__allowed)
-
-
 class ICacheable(Interface):
     """Object that can be associated with a cache manager."""
 
-    cacheId = CacheName(
+    cacheId = Choice(
         title=u"Cache Name",
         description=u"The name of the cache used for this object.",
-        required=True)
+        required=True,
+        vocabulary="Cache Names")
 
     def getCacheId():
         """Gets the associated cache manager ID."""

Deleted: Zope3/trunk/src/zope/app/cache/tests/test_cachename.py
===================================================================
--- Zope3/trunk/src/zope/app/cache/tests/test_cachename.py	2004-07-08 22:20:19 UTC (rev 26244)
+++ Zope3/trunk/src/zope/app/cache/tests/test_cachename.py	2004-07-08 22:23:56 UTC (rev 26245)
@@ -1,59 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Test the CacheName field
-
-In particular, test the proper getting of cache names in allowed_values.
-
-$Id$
-"""
-import unittest
-from zope.interface import implements
-
-from zope.app.tests import setup
-from zope.app.cache.interfaces import CacheName, ICache
-from zope.app.site.tests.placefulsetup import PlacefulSetup
-from zope.app.annotation.interfaces import IAttributeAnnotatable
-from zope.app.utility import LocalUtilityService
-
-
-class CacheStub(object):
-    __name__ = __parent__ = None
-    implements(ICache, IAttributeAnnotatable)
-
-    # IAttributeAnnotatable is implemented so that there will be an
-    # IDependable adapter available.
-
-class CacheNameTest(PlacefulSetup, unittest.TestCase):
-
-    def setUp(self):
-        PlacefulSetup.setUp(self, folders=True)
-        sm = self.makeSite()
-        
-        setup.addService(sm, 'Utilities', LocalUtilityService())
-        setup.addUtility(sm, 'bar', ICache, CacheStub())
-        setup.addUtility(sm, 'baz', ICache, CacheStub())
-        setup.addUtility(sm, 'foo', ICache, CacheStub())
-
-    def test(self):
-        field = CacheName().bind(self.rootFolder)
-        allowed = list(field.allowed_values)
-        allowed.sort()
-        self.assertEqual(allowed, ['', 'bar', 'baz', 'foo'])
-
-
-def test_suite():
-    return unittest.makeSuite(CacheNameTest)
-
-if __name__=='__main__':
-    unittest.main(defaultTest='test_suite')



More information about the Zope3-Checkins mailing list