From d2fc54fb7fd182a0cd87ddd6492306efefcaef2a Mon Sep 17 00:00:00 2001 From: Jason Morgan Date: Thu, 19 Nov 2020 09:18:25 +0000 Subject: [PATCH 1/3] Change Context to RenderingContext --- ticketreminder/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ticketreminder/api.py b/ticketreminder/api.py index c0bb063..e379b2c 100644 --- a/ticketreminder/api.py +++ b/ticketreminder/api.py @@ -5,7 +5,7 @@ from trac.core import * from trac.admin import IAdminCommandProvider from trac.attachment import AttachmentModule -from trac.mimeview import Context +from trac.mimeview import RenderingContext from trac.db import DatabaseManager from trac.env import IEnvironmentSetupParticipant from trac.web import ITemplateStreamFilter, IRequestHandler, IRequestFilter @@ -251,7 +251,7 @@ def filter_stream(self, req, method, filename, stream, data): tags = self._reminder_tags(req, data) if tags: ticket_resource = data['ticket'].resource - context = Context.from_request(req, ticket_resource) + context = RenderingContext.from_request(req, ticket_resource) attachments_data = AttachmentModule(self.env).attachment_data(context) add_stylesheet(req, 'ticketreminder/css/ticketreminder.css') @@ -281,7 +281,7 @@ def _format_reminder(self, req, ticket, id, time, author, origin, description, d when = tag("In ", tag.strong(pretty_timedelta(time)), " (", format_date(time), ")") if description: - context = Context.from_request(req, ticket.resource) + context = RenderingContext.from_request(req, ticket.resource) desc = tag.div(format_to_oneliner(self.env, context, description), class_="description") else: desc = tag() From adcf5d326a27d875f25b21cfb0c76c7cc628872d Mon Sep 17 00:00:00 2001 From: Jason Morgan Date: Thu, 19 Nov 2020 12:36:18 +0000 Subject: [PATCH 2/3] Remove Context and replace with web_context --- setup.py | 2 +- ticketreminder/__init__.py | 2 +- ticketreminder/api.py | 51 ++++++++++++++++++++++++-------------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/setup.py b/setup.py index 30698b5..763a14d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -VERSION = '0.2.1' +VERSION = '0.3.0' PACKAGE = 'ticketreminder' setup( diff --git a/ticketreminder/__init__.py b/ticketreminder/__init__.py index 748c192..4007934 100644 --- a/ticketreminder/__init__.py +++ b/ticketreminder/__init__.py @@ -1,4 +1,4 @@ from api import * import pkg_resources -pkg_resources.require('Trac >= 1.0') +pkg_resources.require('Trac >= 1.3') diff --git a/ticketreminder/api.py b/ticketreminder/api.py index e379b2c..14fdce4 100644 --- a/ticketreminder/api.py +++ b/ticketreminder/api.py @@ -16,7 +16,8 @@ from trac.util.translation import _ from trac.util import get_reporter_id from trac.ticket import Ticket, ITicketChangeListener -from trac.ticket.notification import TicketNotifyEmail +#from trac.ticket.notification import TicketNotifyEmail +from trac.notification.api import NotificationEvent, NotificationSystem from trac.perm import IPermissionRequestor, PermissionError from trac.resource import get_resource_url, get_resource_name @@ -408,8 +409,10 @@ def _do_send(self, id, ticket, author, origin, description): if ticket['status'] != 'closed': reminder = self._format_reminder_text(ticket, id, author, origin, description) - tn = TicketReminderNotifyEmail(self.env, reminder) - tn.notify(ticket) + #tn = TicketReminderNotifyEmail(self.env, reminder) + #tn.notify(ticket) + event = TicketReminderEvent(ticket, ticket['time'], author, reminder) + tn = NotificationSystem(self.env).notify(event) except Exception, e: self.env.log.error("Failure sending reminder notification for ticket #%s: %s", ticket.id, exception_to_unicode(e)) print "Failure sending reminder notification for ticket #%s: %s" % (ticket.id, exception_to_unicode(e)) @@ -421,22 +424,32 @@ def _do_send(self, id, ticket, author, origin, description): """, (id,)) -class TicketReminderNotifyEmail(TicketNotifyEmail): - def __init__(self, env, reminder): - super(TicketReminderNotifyEmail, self).__init__(env) - self.reminder = reminder - - def _notify(self, ticket, newticket=True, modtime=None): - description = ticket.values.get('description') - ticket.values['description'] = self.reminder - super(TicketReminderNotifyEmail, self)._notify(ticket, newticket, modtime) - ticket.values['description'] = description - - def notify(self, ticket): - super(TicketReminderNotifyEmail, self).notify(ticket, newticket=True) - - def format_subj(self, summary, newticket=True): - return super(TicketReminderNotifyEmail, self).format_subj("Ticket reminder", newticket) +#class TicketReminderNotifyEmail(TicketNotifyEmail): +# def __init__(self, env, reminder): +# super(TicketReminderNotifyEmail, self).__init__(env) +# self.reminder = reminder +# +# def _notify(self, ticket, newticket=True, modtime=None): +# description = ticket.values.get('description') +# ticket.values['description'] = self.reminder +# super(TicketReminderNotifyEmail, self)._notify(ticket, newticket, modtime) +# ticket.values['description'] = description +# +# def notify(self, ticket): +# super(TicketReminderNotifyEmail, self).notify(ticket, newticket=True) +# +# def format_subj(self, summary, newticket=True): +# return super(TicketReminderNotifyEmail, self).format_subj("Ticket reminder", newticket) + +class TicketReminderEvent(NotificationEvent): + """Represent a ticket reminder `NotificationEvent`.""" + + def __init__(self, target, time, author, comment=None): + + super(TicketChangeEvent, self).__init__('ticket', 'reminder', target, + time, author) + self.comment = comment + self.changes = {} def clear_time(date): From 7f4b3d2b6e4738bb63ab8cbe3ed070bf3547fb5c Mon Sep 17 00:00:00 2001 From: Jason Morgan Date: Thu, 19 Nov 2020 12:42:15 +0000 Subject: [PATCH 3/3] previous commit was not the latest --- ticketreminder/api.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ticketreminder/api.py b/ticketreminder/api.py index 14fdce4..2791001 100644 --- a/ticketreminder/api.py +++ b/ticketreminder/api.py @@ -5,7 +5,7 @@ from trac.core import * from trac.admin import IAdminCommandProvider from trac.attachment import AttachmentModule -from trac.mimeview import RenderingContext +#from trac.mimeview import RenderingContext from trac.db import DatabaseManager from trac.env import IEnvironmentSetupParticipant from trac.web import ITemplateStreamFilter, IRequestHandler, IRequestFilter @@ -25,6 +25,8 @@ from genshi.builder import tag from genshi.filters import Transformer +from trac.web.chrome import web_context + import db_default @@ -252,7 +254,7 @@ def filter_stream(self, req, method, filename, stream, data): tags = self._reminder_tags(req, data) if tags: ticket_resource = data['ticket'].resource - context = RenderingContext.from_request(req, ticket_resource) + context = web_context(req, ticket_resource) attachments_data = AttachmentModule(self.env).attachment_data(context) add_stylesheet(req, 'ticketreminder/css/ticketreminder.css') @@ -282,7 +284,7 @@ def _format_reminder(self, req, ticket, id, time, author, origin, description, d when = tag("In ", tag.strong(pretty_timedelta(time)), " (", format_date(time), ")") if description: - context = RenderingContext.from_request(req, ticket.resource) + context = web_context(req, ticket.resource) desc = tag.div(format_to_oneliner(self.env, context, description), class_="description") else: desc = tag()