Bugfix while displaying content of textarea-entered text (Strings with format=String.TEXT): for displaying again textarea content, I replaced 'backslash n' with html br tags, but in some cases carriage returns are stored as a sequence of 'backslah r' and 'backslah n' chars. In this case, 'backslash r' chars were left alone in the HTML page, producing sometimes strange behaviour within the browser.

This commit is contained in:
Gaetan Delannay 2011-02-23 11:30:44 +01:00
parent 3fc5bc8418
commit 39321b2d38
5 changed files with 25 additions and 12 deletions

View file

@ -1 +1 @@
0.6.3 0.6.4

View file

@ -1162,6 +1162,18 @@ class BaseMixin:
if '-' in res: res = res[:res.find('-')] if '-' in res: res = res[:res.find('-')]
return res return res
def formatText(self, text, format='html'):
'''Produces a representation of p_text into the desired p_format, which
is 'html' by default.'''
if format in ('html', 'xhtml'):
res = text.replace('\r\n', '<br/>').replace('\n', '<br/>')
elif format == 'js':
res = text.replace('\r\n', '').replace('\n', '')
res = res.replace("'", "\\'")
else:
res = text
return res
def translate(self, label, mapping={}, domain=None, default=None, def translate(self, label, mapping={}, domain=None, default=None,
language=None, format='html'): language=None, format='html'):
'''Translates a given p_label into p_domain with p_mapping.''' '''Translates a given p_label into p_domain with p_mapping.'''
@ -1196,11 +1208,7 @@ class BaseMixin:
if not res: res = label if not res: res = label
else: else:
# Perform replacements, according to p_format. # Perform replacements, according to p_format.
if format == 'html': res = self.formatText(res, format)
res = res.replace('\r\n', '<br/>').replace('\n', '<br/>')
elif format == 'js':
res = res.replace('\r\n', '').replace('\n', '')
res = res.replace("'", "\\'")
# Perform variable replacements # Perform variable replacements
for name, repl in mapping.iteritems(): for name, repl in mapping.iteritems():
res = res.replace('${%s}' % name, repl) res = res.replace('${%s}' % name, repl)

View file

@ -13,7 +13,7 @@
</span> </span>
<tal:formattedString condition="python: fmt not in (0, 3)"> <tal:formattedString condition="python: fmt not in (0, 3)">
<span tal:condition="python: value and (fmt == 1)" <span tal:condition="python: value and (fmt == 1)"
tal:replace="structure python: value.replace('\n', '&lt;br&gt;')"/> tal:replace="structure python: contextObj.formatText(value, format='html')"/>
<span tal:condition="python: value and (fmt == 2)" tal:replace="structure value"/> <span tal:condition="python: value and (fmt == 2)" tal:replace="structure value"/>
</tal:formattedString> </tal:formattedString>
</metal:view> </metal:view>

View file

@ -378,7 +378,7 @@ class AbstractWrapper:
self.o.reindexObject() self.o.reindexObject()
def export(self, at='string', format='xml', include=None, exclude=None): def export(self, at='string', format='xml', include=None, exclude=None):
'''Creates an "exportable" version of this object. p_format is XML by '''Creates an "exportable" version of this object. p_format is "xml" by
default, but can also be "csv". If p_format is: default, but can also be "csv". If p_format is:
* "xml", if p_at is "string", this method returns the XML version, * "xml", if p_at is "string", this method returns the XML version,
without the XML prologue. Else, (a) if not p_at, the XML without the XML prologue. Else, (a) if not p_at, the XML
@ -427,4 +427,9 @@ class AbstractWrapper:
p_data must be a dictionary whose keys are field names (strings) and p_data must be a dictionary whose keys are field names (strings) and
whose values are the previous field values.''' whose values are the previous field values.'''
self.o.addDataChange(data) self.o.addDataChange(data)
def formatText(self, text, format='html'):
'''Produces a representation of p_text into the desired p_format, which
is 'html' by default.'''
return self.o.formatText(text, format)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View file

@ -80,12 +80,12 @@ class Converter:
'''Returns the absolute path of the input file. In fact, it returns a '''Returns the absolute path of the input file. In fact, it returns a
tuple with some URL version of the path for OO as the first element tuple with some URL version of the path for OO as the first element
and the absolute path as the second element.''' and the absolute path as the second element.'''
import uno import unohelper
if not os.path.exists(docPath) and not os.path.isfile(docPath): if not os.path.exists(docPath) and not os.path.isfile(docPath):
raise ConverterError(DOC_NOT_FOUND % docPath) raise ConverterError(DOC_NOT_FOUND % docPath)
docAbsPath = os.path.abspath(docPath) docAbsPath = os.path.abspath(docPath)
# Return one path for OO, one path for me. # Return one path for OO, one path for me.
return uno.systemPathToFileUrl(docAbsPath), docAbsPath return unohelper.systemPathToFileUrl(docAbsPath), docAbsPath
def getResultFilter(self): def getResultFilter(self):
'''Based on the result type, identifies which OO filter to use for the '''Based on the result type, identifies which OO filter to use for the
@ -110,7 +110,7 @@ class Converter:
different extension: different extension:
<inputFileName>.<resultType> <inputFileName>.<resultType>
''' '''
import uno import unohelper
baseName = os.path.splitext(self.docPath)[0] baseName = os.path.splitext(self.docPath)[0]
if self.resultType != self.inputType: if self.resultType != self.inputType:
res = '%s.%s' % (baseName, self.resultType) res = '%s.%s' % (baseName, self.resultType)
@ -121,7 +121,7 @@ class Converter:
f.write('Hello') f.write('Hello')
f.close() f.close()
os.remove(res) os.remove(res)
return uno.systemPathToFileUrl(res) return unohelper.systemPathToFileUrl(res)
except (OSError, IOError), ioe: except (OSError, IOError), ioe:
raise ConverterError(CANNOT_WRITE_RESULT % (res, ioe)) raise ConverterError(CANNOT_WRITE_RESULT % (res, ioe))