[Zope-CVS] CVS: Products/CompositePage - composite.py:1.12 slot.py:1.18

Shane Hathaway shane at zope.com
Tue Mar 2 17:09:16 EST 2004


Update of /cvs-repository/Products/CompositePage
In directory cvs.zope.org:/tmp/cvs-serv9946

Modified Files:
	composite.py slot.py 
Log Message:
Improved error handling in manual interface.


=== Products/CompositePage/composite.py 1.11 => 1.12 ===
--- Products/CompositePage/composite.py:1.11	Tue Mar  2 10:28:38 2004
+++ Products/CompositePage/composite.py	Tue Mar  2 17:08:45 2004
@@ -22,13 +22,14 @@
 import Acquisition
 from Acquisition import aq_base, aq_inner, aq_parent, aq_get
 from OFS.Folder import Folder
+from OFS.SimpleItem import SimpleItem
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
 from AccessControl import ClassSecurityInfo
 from AccessControl.ZopeGuards import guarded_getattr
 
 from interfaces import ISlot, CompositeError
-from slot import Slot, getIconURL
+from slot import Slot, getIconURL, formatException
 from macro import renderMacro, getRootMacro
 import perm_names
 
@@ -219,10 +220,17 @@
             index = 0
             slot_values = slot.objectValues()
             for element in slot_values:
-                icon = getIconURL(element, icon_base_url)
+                error = None
+                try:
+                    ob = element.dereference()
+                except:
+                    error = formatException(self, editing=1)
+                    ob = FailedElement().__of__(self)
+                icon = getIconURL(ob, icon_base_url)
                 element_info = {
-                    'title': element.title_or_id(),
+                    'title': ob.title_or_id(),
                     'icon': icon,
+                    'error': error,
                     'source_path': '/'.join(element.getPhysicalPath()),
                     'index': index,
                     'next_index': index + 1,
@@ -260,6 +268,13 @@
     def all_meta_types(self):
         return Folder.all_meta_types(self, interfaces=(ISlot,))
 
+
+
+class FailedElement(SimpleItem):
+    meta_type = "Failed Element"
+    icon = 'p_/broken'
+    id = 'error'
+    title = 'Error'
 
 
 class AddOnChangeJar:


=== Products/CompositePage/slot.py 1.17 => 1.18 ===
--- Products/CompositePage/slot.py:1.17	Tue Mar  2 15:41:44 2004
+++ Products/CompositePage/slot.py	Tue Mar  2 17:08:45 2004
@@ -167,7 +167,7 @@
                 # Ugly ZODB requirement: don't catch ConflictErrors
                 raise
             except:
-                text = self._handleError(editing)
+                text = formatException(self, editing)
 
             if editing:
                 o2 = obj.dereference()
@@ -185,32 +185,6 @@
 
         return res
 
-
-    def _handleError(self, editing):
-        exc_info = sys.exc_info()
-        try:
-            if editing:
-                # Show editors the real error
-                t, v = exc_info[:2]
-                t = getattr(t, '__name__', t)
-                msg = "An error occurred. %s" % (
-                    escape(('%s: %s' % (t, v))[:80]))
-            else:
-                # Show viewers a simplified error with a number
-                msg = ("An error occurred while generating "
-                        "this part of the page.")
-            try:
-                log = aq_get(self, '__error_log__', None, 1)
-            except AttributeError:
-                LOG("Composite", ERROR, "Error in a page element",
-                    error=exc_info)
-                return msg
-            else:
-                error_log_url = log.raising(exc_info)
-                return error_tag % (msg, error_log_url)
-        finally:
-            del exc_info
-
 Globals.InitializeClass(Slot)
 
 
@@ -229,6 +203,36 @@
     return icon
 
 
+def formatException(context, editing):
+    """Returns an HTML-ified error message.
+
+    If not editing, the message includes no details.
+    """
+    exc_info = sys.exc_info()
+    try:
+        if editing:
+            # Show editors the real error
+            t, v = exc_info[:2]
+            t = getattr(t, '__name__', t)
+            msg = "An error occurred. %s" % (
+                escape(('%s: %s' % (t, v))[:80]))
+        else:
+            # Show viewers a simplified error.
+            msg = ("An error occurred while generating "
+                    "this part of the page.")
+        try:
+            log = aq_get(context, '__error_log__', None, 1)
+        except AttributeError:
+            LOG("Composite", ERROR, "Error in a page element",
+                error=exc_info)
+            return msg
+        else:
+            error_log_url = log.raising(exc_info)
+            return error_tag % (msg, error_log_url)
+    finally:
+        del exc_info
+
+
 addSlotForm = PageTemplateFile("addSlotForm", _www)
 
 def manage_addSlot(dispatcher, id, REQUEST=None):
@@ -238,6 +242,7 @@
     dispatcher._setObject(ob.getId(), ob)
     if REQUEST is not None:
         return dispatcher.manage_main(dispatcher, REQUEST)
+
 
 def manage_generateSlots(dispatcher, REQUEST=None):
     """Adds all slots requested by a template to a composite.




More information about the Zope-CVS mailing list