Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve MessageDialogs and exception views as text/html #1081

Merged

Conversation

perrinjerome
Copy link
Contributor

Now that Zope uses text/plain by default, MessageDialogs were served as text/plain. Keep compatibility by returning a special string with asHTML method, that ZPublisher.HTTPResponse.HTTPResponse.setBody understands.

MessageDialogs are deprecated and do not integrate well in Zope >= 4 ZMI, but they are used in some old products.

Fixes issues discussed in #1079 (comment)

@perrinjerome
Copy link
Contributor Author

image

looks odd in the new ZMI, but it's better than

image


This implementation is a bit tricky, it uses

if hasattr(body, 'asHTML'):
body = body.asHTML()
if content_type is None:
content_type = 'text/html'
the MessageDialogs are supposed to be returned directly ( see https://github.com/nakagami/Products.ZSQLiteDA/blob/c89c190f9572070607893ee09f627c3862370905/Products/ZSQLiteDA/DA.py#L128-L133 ), so at this level we don't have access to requests and response

/cc @dataflake @GiaBen

@perrinjerome
Copy link
Contributor Author

the test on zope 4 seems to show a regression with this approach

Now that Zope uses text/plain by default, MessageDialogs were served as
text/plain. Keep compatibility by returning a special string with
`asHTML` method, that ZPublisher.HTTPResponse.HTTPResponse.setBody
understands.

MessageDialogs are deprecated and do not integrate well in Zope >= 4
ZMI, but they are used in some old products.
@perrinjerome perrinjerome force-pushed the fix/MessageDialog_asHTML branch from a383f02 to c5410e7 Compare December 17, 2022 15:23
@perrinjerome perrinjerome marked this pull request as ready for review December 17, 2022 15:25
@perrinjerome
Copy link
Contributor Author

the test on zope 4 seems to show a regression with this approach

It's OK now.

For the details: in the previous version I was changing App.special_dtml.HTML to return html and this made this DTML Document with content index served as text/html instead of the expected text/plain

self.folder.addDTMLDocument('index_html', file='index')

@dataflake dataflake changed the title Restore serving MessageDialogs as text/html Serve MessageDialogs and exception views as text/html Dec 18, 2022
@perrinjerome
Copy link
Contributor Author

Thanks @dataflake for the amendments 👍

@dataflake dataflake merged commit 424683e into zopefoundation:master Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants