Beispiel #1
0
 def html_diff(self, context=True, wrapcolumn=40):
     """Return an HTML table showing differences"""
     # difflib is not Unicode-aware, so we need to force everything to
     # utf-8 manually
     a = [safe_unicode(i) for i in self._parseField(self.oldValue, filename=self.oldFilename)]
     b = [safe_unicode(i) for i in self._parseField(self.newValue, filename=self.newFilename)]
     vis_diff = difflib.HtmlDiff(wrapcolumn=wrapcolumn)
     diff = safe_utf8(vis_diff.make_table(a, b, safe_unicode(self.id1), safe_unicode(self.id2), context=context))
     return diff
Beispiel #2
0
    def _parseField(self, value, filename=None):
        if value is None:
            value = ''

        # In tests translation is not available, so we account for this
        # case here.
        translate = getattr(getSite(), 'translate', None)
        if translate is not None:
            value = translate(_(value))

        return TextDiff._parseField(self, safe_unicode(value), filename)
Beispiel #3
0
 def html_diff(self, context=True, wrapcolumn=40):
     """Return an HTML table showing differences"""
     # difflib is not Unicode-aware, so we need to force everything to
     # utf-8 manually
     a = [
         safe_unicode(i)
         for i in self._parseField(self.oldValue, filename=self.oldFilename)
     ]
     b = [
         safe_unicode(i)
         for i in self._parseField(self.newValue, filename=self.newFilename)
     ]
     vis_diff = difflib.HtmlDiff(wrapcolumn=wrapcolumn)
     diff = safe_utf8(
         vis_diff.make_table(a,
                             b,
                             safe_unicode(self.id1),
                             safe_unicode(self.id2),
                             context=context))
     return diff
Beispiel #4
0
    def _parseField(self, value, filename=None):
        if value is None:
            value = ''

        # In tests translation is not available, so we account for this
        # case here.
        translate = getattr(getSite(), 'translate', None)
        if translate is not None:
            value = translate(_(value))

        return TextDiff._parseField(self, safe_unicode(value), filename)