Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for trac 1.4 #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = '0.2.1'
VERSION = '0.3.0'
PACKAGE = 'ticketreminder'

setup(
Expand Down
2 changes: 1 addition & 1 deletion ticketreminder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from api import *
import pkg_resources

pkg_resources.require('Trac >= 1.0')
pkg_resources.require('Trac >= 1.3')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes you made should be compatible with 1.2 as well. Could we set this to 1.2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can test it, sure

59 changes: 37 additions & 22 deletions ticketreminder/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,14 +16,17 @@
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

from genshi.core import Markup
from genshi.builder import tag
from genshi.filters import Transformer

from trac.web.chrome import web_context

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this into the from trac.* block of imports.

import db_default


Expand Down Expand Up @@ -251,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 = Context.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')
Expand Down Expand Up @@ -281,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 = Context.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()
Expand Down Expand Up @@ -408,8 +411,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))
Expand All @@ -421,22 +426,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class may not be necessary. TicketChangeEvent has a 6th arg comment. Can TicketChangeEvent be used instead?

self.comment = comment
self.changes = {}


def clear_time(date):
Expand Down