freebsd-ports/www/trac-announcer/files/patch-old-ticket-link-style
Philip M. Gollucci 6c3241dda1 The AnnouncerPlugin is meant to provide an extensible,
user-customizable notification system that can be used
to completely replace Trac's default notifications.

WWW: http://trac-hacks.org/wiki/AnnouncertPlugin

PR:		ports/150484
Submitted by:	Eygene Ryabinkin <rea-fbsd at codelabs.ru>
2010-10-12 06:21:13 +00:00

80 lines
2.8 KiB
Text

--- ./announcer/formatters/ticket.py.orig 2010-09-10 19:37:52.000000000 +0400
+++ ./announcer/formatters/ticket.py 2010-09-10 21:03:38.000000000 +0400
@@ -36,7 +36,7 @@
from genshi.template import NewTextTemplate, MarkupTemplate
from genshi.template import TemplateLoader
-from trac.config import Option, IntOption, ListOption
+from trac.config import Option, IntOption, ListOption, BoolOption
from trac.core import *
from trac.mimeview import Context
from trac.test import Mock, MockPerm
@@ -72,6 +72,11 @@
'owner, reporter, milestone, priority, severity',
doc="""Comma seperated list of fields to appear in tickets.
Use * to include all headers.""")
+
+ ticket_link_with_comment = BoolOption('announcer',
+ 'ticket_link_with_comment',
+ 'false',
+ """Include last change anchor to the ticket URL.""")
def styles(self, transport, realm):
if realm == "ticket":
@@ -89,6 +94,38 @@
elif style == "text/html":
return self._format_html(event)
+ def _ticket_link(self, ticket):
+ ticket_link = self.env.abs_href('ticket', ticket.id)
+ if self.ticket_link_with_comment == False:
+ return ticket_link
+
+ cnum = self._ticket_last_comment(ticket)
+ if cnum != None:
+ ticket_link += "#comment:%s" % str(cnum)
+
+ return ticket_link
+
+ def _ticket_last_comment(self, ticket):
+ cnum = -1
+
+ for entry in ticket.get_changelog():
+ (time, author, field, oldvalue, newvalue, permanent) = entry
+ if field != "comment":
+ continue
+
+ try:
+ n = int(oldvalue)
+ except:
+ continue
+
+ if cnum < n:
+ cnum = n
+
+ if cnum == -1:
+ return None
+ else:
+ return cnum
+
def _format_plaintext(self, event):
ticket = event.target
short_changes = {}
@@ -109,7 +146,7 @@
comment = event.comment,
fields = self._header_fields(ticket),
category = event.category,
- ticket_link = self.env.abs_href('ticket', ticket.id),
+ ticket_link = self._ticket_link(ticket),
project_name = self.env.project_name,
project_desc = self.env.project_description,
project_link = self.env.project_url or self.env.abs_href(),
@@ -189,7 +226,7 @@
fields = self._header_fields(ticket),
comment = temp,
category = event.category,
- ticket_link = self.env.abs_href('ticket', ticket.id),
+ ticket_link = self._ticket_link(ticket),
project_name = self.env.project_name,
project_desc = self.env.project_description,
project_link = self.env.project_url or self.env.abs_href(),