[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Caching/Views/Browser - CacheableView.py:1.2 edit.pt:1.2

Jim Fulton jim@zope.com
Mon, 11 Nov 2002 15:57:21 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Caching/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv20886/Views/Browser

Modified Files:
	CacheableView.py edit.pt 
Log Message:

Changed the cacheName field to implement allowed_values, rather than
items and to use bound context rather than context wrappers.

Changed the cachable editing view to use a standard editing widget and
the new widget setup code in Zope.App.Forms.Utility.

Got rid of an unused import of FormView.



=== Zope3/lib/python/Zope/App/Caching/Views/Browser/CacheableView.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/Caching/Views/Browser/CacheableView.py:1.1	Wed Oct  9 09:08:44 2002
+++ Zope3/lib/python/Zope/App/Caching/Views/Browser/CacheableView.py	Mon Nov 11 15:57:20 2002
@@ -20,7 +20,6 @@
 from Zope.App.OFS.Annotation.IAnnotatable import IAnnotatable
 from Zope.App.Caching.Caching import getCacheForObj
 from Zope.App.PageTemplate import ViewPageTemplateFile
-#from Zope.App.Forms.Views.Browser.FormView import FormView
 from Zope.Publisher.Browser.BrowserView import BrowserView
 from Zope.App.Forms.Widget import CustomWidget
 from Zope.App.Forms.Views.Browser import Widget
@@ -29,6 +28,7 @@
 from Zope.Schema.Exceptions import StopValidation, ValidationError, \
      ValidationErrorsAll, ConversionErrorsAll
 from Zope.App.Forms.Exceptions import WidgetInputError
+from Zope.App.Forms.Utility import setUpEditWidgets
 
 class CacheableView(BrowserView):
 
@@ -36,6 +36,11 @@
     
     form = ViewPageTemplateFile("edit.pt")
 
+    def __init__(self, *args):
+        super(CacheableView, self).__init__(*args)
+        self.cachable = getAdapter(self.context, ICacheable)
+        setUpEditWidgets(self, ICacheable, self.cachable)
+
     def invalidate(self):
         "Invalidate the current cached value."
 
@@ -49,26 +54,15 @@
     def action(self):
         "Change the cacheId"
         try:
-            cacheId = self._getCacheIdWidget().getData()
+            cacheId = self.cacheId.getData()
         except (ValidationErrorsAll, ConversionErrorsAll), e:
             return self.form(errors=e)
         except WidgetInputError, e:
             #return self.form(errors=e.errors)
             return repr(e.errors)
         else:
-            getAdapter(self.context, ICacheable).setCacheId(cacheId)
+            self.cachable.setCacheId(cacheId)
             return self.form(message="Saved changes.")
-
-    def renderCacheId(self):
-        cacheId = getAdapter(self.context, ICacheable).getCacheId()
-        return self._getCacheIdWidget().render(cacheId)
-    
-    def _getCacheIdWidget(self):
-        cacheId = getAdapter(self.context, ICacheable).getCacheId()
-        field = ICacheable.getDescriptionFor('cacheId')
-        field = ContextWrapper(field, self.context)
-        w = CustomWidget(Widget.ListWidget, size=1)
-        return w(field, self.request)
 
 
 


=== Zope3/lib/python/Zope/App/Caching/Views/Browser/edit.pt 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/Caching/Views/Browser/edit.pt:1.1	Wed Oct  9 09:08:44 2002
+++ Zope3/lib/python/Zope/App/Caching/Views/Browser/edit.pt	Mon Nov 11 15:57:20 2002
@@ -22,13 +22,14 @@
         <tr>
           <th class="EditAttributeName">Cache name</th>
           <td class="EditAttributeValue"
-              tal:content="structure python: view.renderCacheId()">
+              tal:content="structure view/cacheId">
             <input size="20" />
           </td>
         </tr>
       </table>
 
-      <input type="submit" name="ChangeCaching.html:method" value="Save Changes" />
+      <input type="submit" name="ChangeCaching.html:method" 
+             value="Save Changes" />
       <input type="submit" name="InvalidateCache.html:method"
              value="Invalidate Cached Value" />