Updated exceptions views
authorThierry Florac <thierry.florac@onf.fr>
Wed, 14 May 2014 15:48:26 +0200
changeset 21 68861235109e
parent 20 7ff249908910
child 22 6ef4b364250a
Updated exceptions views
src/ztfy/myams/configure.zcml
src/ztfy/myams/page.py
--- a/src/ztfy/myams/configure.zcml	Wed May 14 15:48:09 2014 +0200
+++ b/src/ztfy/myams/configure.zcml	Wed May 14 15:48:26 2014 +0200
@@ -114,6 +114,20 @@
 		permission="zope.Public" />
 
 	<browser:page
+		name="index.html"
+		for="zope.security.interfaces.IUnauthorized"
+		class=".page.UnauthorizedExceptionView"
+		layer=".layer.MyAMSLayer"
+		permission="zope.Public" />
+
+	<browser:page
+		name="index.html"
+		for="zope.security.interfaces.IUnauthorized"
+		class=".page.UnauthorizedExceptionView"
+		layer="z3c.jsonrpc.interfaces.IJSONRPCRequest"
+		permission="zope.Public" />
+
+	<browser:page
 		name="error"
 		for="zope.security.interfaces.IUnauthorized"
 		class=".page.UnauthorizedExceptionView"
--- a/src/ztfy/myams/page.py	Wed May 14 15:48:09 2014 +0200
+++ b/src/ztfy/myams/page.py	Wed May 14 15:48:26 2014 +0200
@@ -8,13 +8,13 @@
 from datetime import datetime
 
 # import Zope3 interfaces
+from persistent.interfaces import IPersistent
 from z3c.json.interfaces import IJSONWriter
 from z3c.template.interfaces import ILayoutTemplate
 from zope.authentication.interfaces import IAuthentication
 from zope.pagetemplate.interfaces import IPageTemplate
 
 # import local interfaces
-from zope.traversing.browser.absoluteurl import absoluteURL
 from ztfy.myams.interfaces import IInnerPage, IModalPage
 
 # import Zope3 packages
@@ -23,11 +23,15 @@
 from zope.i18n import translate
 from zope.interface import implements
 from zope.publisher.browser import BrowserPage
+from zope.traversing.browser.absoluteurl import absoluteURL
 
 # import local packages
 from ztfy.utils.date import formatDatetime
 from ztfy.utils.text import textToHTML
 from ztfy.utils.timezone import tztime
+from ztfy.utils.traversing import getParent
+
+from ztfy.myams import _
 
 
 class BaseTemplateBasedPage(BrowserPage):
@@ -101,9 +105,12 @@
         return '%s (%s)' % (principal.title, principal.id)
 
     def __call__(self):
+        self.request.response.setStatus(500)
         writer = getUtility(IJSONWriter)
         return writer.write({'status': 'messagebox',
                              'messagebox': {'status': 'error',
+                                            'title': translate(_("An error occurred: %s"), context=self.request) %
+                                                     self.error_name,
                                             'content': self.error_message,
                                             'number': self.error_datetime,
                                             'icon': 'fa fa-warning animated shake'}})
@@ -116,6 +123,8 @@
         principal = self.request.principal
         auth = getUtility(IAuthentication)
         auth.unauthorized(principal.id, self.request)
+        self.request.response.setStatus(200)
+        parent = getParent(self.context, IPersistent)
         writer = getUtility(IJSONWriter)
         return writer.write({'status': 'modal',
-                             'location': 'login-dialog.html?came_from=%s' % absoluteURL(self.context, self.request)})
+                             'location': 'login-dialog.html?came_from=%s' % absoluteURL(parent, self.request)})