Line output in Plone python script

I created a portlet product for binding to an external chat system. I use configlet with WYSIWYGWidget (among others) and portal_properties to store some properties.

What gives me the question is that I pass these values ​​to the auto_popup.js.pt property and create a time delay popup with the contents of WYSIWYGWidget, but if there is a newline character in the html WYSIWYGWidget between the tags causes an error in my javascript. I can fix this by simply going to portal_properties and manually deleting the newline character (which appears as a space in the line field), but that is not the point.

The solution I was working with uses a python script to translate html from the property field (which is escaped) to standard html and also remove the newline character. The script call works fine, and the script works fine in testing, but for some reason it won't work when it calls a specific object from portal_properties.

In the code below, I commented on the actual value of the property that I am working with for testing. At startup, as in plone, the only replacement () that goes through is replacing the “hello” with “hello,” but if you use a commented value, it all works.

Any suggestions are welcome.

from Products.CMFCore.utils import getToolByName

properties = getToolByName(context, 'portal_properties')
chatMessage = properties.chat_properties.chat_message

# chatMessage = '''<h2 style="text-align: center; ">Welcome</h2>
# <h3 style="text-align: center; ">Would you like to talk to Keith?</h3>'''

chatMessage = chatMessage.replace(">", ">")
chatMessage = chatMessage.replace("&lt;", "<")
chatMessage = chatMessage.replace("&amp;", "&")
chatMessage = chatMessage.replace("> <", "><")
chatMessage = chatMessage.replace('>\n<', '><')
chatMessage = chatMessage.replace('Welcome', 'Hello')

#print chatMessage
return chatMessage
+3
source share
2 answers

urllib.quote() urllib.unquote()

+1

:

from Products.PythonScripts.standard import url_unquote
chatMessage = url_unquote(properties.chat_properties.chat_message)
+1

All Articles