--- trac/ticket/notification.py 2011-04-04 15:03:25.000000000 +0200
+++ trac/ticket/notification.py 2011-04-04 15:16:17.000000000 +0200
@@ -29,6 +29,21 @@
from trac.util.text import CRLF, wrap, obfuscate_email_address, to_unicode
from trac.util.translation import deactivate, reactivate
+from trac.versioncontrol.diff import diff_blocks
+from genshi import HTML
+import difflib
+
+def diff_cleanup(gen):
+ for value in gen:
+ if value.startswith('---'):
+ continue
+ if value.startswith('+++'):
+ continue
+ if value.startswith('@@'):
+ yield '\n'
+ else:
+ yield value
+
class TicketNotificationSystem(Component):
always_notify_owner = BoolOption('notification', 'always_notify_owner',
@@ -106,6 +120,7 @@
change_data = {}
link = self.env.abs_href.ticket(ticket.id)
summary = self.ticket['summary']
+ BRCRLF = '
' + CRLF
if not self.newticket and modtime: # Ticket change
from trac.ticket.web_ui import TicketModule
@@ -124,29 +139,32 @@
new = values['new']
newv = ''
if field == 'description':
- new_descr = wrap(new, self.COLS, ' ', ' ', CRLF)
- old_descr = wrap(old, self.COLS, '> ', '> ', CRLF)
- old_descr = old_descr.replace(2 * CRLF, CRLF + '>' + \
- CRLF)
- cdescr = CRLF
- cdescr += 'Old description:' + 2 * CRLF + old_descr + \
- 2 * CRLF
- cdescr += 'New description:' + 2 * CRLF + new_descr + \
- CRLF
- changes_descr = cdescr
+ changes_descr = HTML(
+ "%s" % (
+ '\n'.join(
+ diff_cleanup(
+ difflib.unified_diff(
+ wrap(old, cols=60).split('\n'),
+ wrap(new, cols=60).split('\n'),
+ lineterm='', n=3
+ )
+ )
+ ).strip()
+ )
+ )
elif field == 'summary':
summary = "%s (was: %s)" % (new, old)
elif field == 'cc':
(addcc, delcc) = self.diff_cc(old, new)
chgcc = ''
if delcc:
- chgcc += wrap(" * cc: %s (removed)" %
- ', '.join(delcc),
- self.COLS, ' ', ' ', CRLF) + CRLF
+ chgcc += '
%s: | %s | ','%s: | %s | ' + CRLF else: - # Note: f['label'] is a Babel's LazyObject, make sure its - # __str__ method won't be called. - str_tmp = u'%s: %s' % (f['label'], unicode(fval)) - idx = i % 2 - cell_tmp[idx] += wrap(str_tmp, width_lr[idx] - 2 + 2 * idx, - (width[2 * idx] - - self.get_text_width(f['label']) - + 2 * idx) * ' ', - 2 * ' ', CRLF) - cell_tmp[idx] += CRLF + txt += format[i % 2] % (f['label'].capitalize(), unicode(fval)) i += 1 - cell_l = cell_tmp[0].splitlines() - cell_r = cell_tmp[1].splitlines() - for i in range(max(len(cell_l), len(cell_r))): - if i >= len(cell_l): - cell_l.append(width_l * ' ') - elif i >= len(cell_r): - cell_r.append('') - fmt_width = width_l - self.get_text_width(cell_l[i]) \ - + len(cell_l[i]) - txt += u'%-*s|%s%s' % (fmt_width, cell_l[i], cell_r[i], CRLF) if big: txt += sep for name, value in big: - txt += CRLF.join(['', name + ':', value, '', '']) + txt += CRLF.join([' |
---|---|---|---|
' + name + ':' + ' | |||
' + value + ' |