Skip to content

Commit

Permalink
- improve finding the actual published object, and use existing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Apr 27, 2019
1 parent 0112094 commit 297154f
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/OFS/browser/__init__.py
Expand Up @@ -11,24 +11,35 @@
#
##############################################################################

from Acquisition import aq_base
from Acquisition import aq_parent
from Products.Five import BrowserView


raiser = 'raise_standardErrorMessage'


class StandardErrorMessageView(BrowserView):
""" View rendered on SiteError.
Requires a DTML Method named ``standard_error_message``
Requires a callable object named ``standard_error_message`` on the
published object's acquisition path. The callable can be a DTML Method,
DTML Document, Python Script or Page Template.
"""

def __call__(self):
published = getattr(self.request, 'PUBLISHED', None)
if published is not None:
root = aq_parent(published)
else:
root = self.request['PARENTS'][0]

return root.standard_error_message(
client=root,
pub = getattr(self.request, 'PUBLISHED', self.request['PARENTS'][0])
parent = aq_parent(pub)

if pub is not None and parent is None:
# The published object is not an instance or not wrapped
pub = self.request['PARENTS'][0]
parent = aq_parent(pub)

if getattr(aq_base(pub), raiser, None) is not None:
return getattr(pub, raiser)(REQUEST=self.request)[1]

return parent.standard_error_message(
client=parent,
error_type=self.context.__class__.__name__,
error_value=str(self.context))

0 comments on commit 297154f

Please sign in to comment.