summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Vagelpohl <jens@netz.ooo>2005-02-07 10:21:47 +0000
committerJens Vagelpohl <jens@netz.ooo>2005-02-07 10:21:47 +0000
commit0723fa38acaecf36a5518847cf38b1470a308aa9 (patch)
tree3cebb14be9b6316da0dfecc06a85e74c55f9d69c
parent4e3e8bbaa3982c774ec9159cf1b5ff7f48db2921 (diff)
downloadJTracker-0723fa38acaecf36a5518847cf38b1470a308aa9.zip
JTracker-0723fa38acaecf36a5518847cf38b1470a308aa9.tar.gz
- make all mail templates customizable
- finish work on customizable phrases
-rw-r--r--CHANGES.txt3
-rw-r--r--JTracker.py138
-rw-r--r--JTrackerIssue.py50
-rw-r--r--www/translateJTracker.pt12
4 files changed, 131 insertions, 72 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index c458495..6472a09 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,9 @@ CHANGES.txt for the JTracker
JTracker has been added. A new "translate" method can be
used to pull the translated value into your view templates.
+ - Along with the internal phrases the templates used to generate
+ email notices are fully customizable, too.
+
Bugs fixed:
- Worked around a bug in Zope 2.7.1 and up by removing the
diff --git a/JTracker.py b/JTracker.py
index 50ce80d..a651d9e 100644
--- a/JTracker.py
+++ b/JTracker.py
@@ -32,31 +32,48 @@ from Permissions import ManageJTracker, SubmitJTrackerIssues
from Permissions import SupportJTrackerIssues
from JTrackerIssue import JTrackerIssue, manage_addJTrackerIssue
from utils import setupCatalog, initializeSecurity
-from utils import NEW_ISSUE_TEMPLATE, MAIL_ERROR_TEMPLATE
+from utils import NEW_ISSUE_TEMPLATE, MAIL_ERROR_TEMPLATE, REPLY_TEMPLATE
_wwwdir = os.path.join(package_home(globals()), 'www')
addJTrackerForm = PageTemplateFile('addJTracker.pt', _wwwdir)
+TRANSLATIONS = { 'Pending' : 'Pending'
+ , 'Accepted' : 'Accepted'
+ , 'Deferred' : 'Deferred'
+ , 'Rejected' : 'Rejected'
+ , 'Resolved' : 'Resolved'
+ , 'Missing values for' : 'Missing values for'
+ , 'Invalid email address' : 'Invalid email address'
+ , 'File size too large, limit is': 'File size too large, limit is'
+ , 'Title' : 'Title'
+ , 'Request type' : 'Request Type'
+ , 'Component' : 'Component'
+ , 'Description' : 'Description'
+ , 'Requester Name' : 'Requester Name'
+ , 'Requester Email' : 'Requester Email'
+ , 'Initial Request' : 'Initial Request'
+ , 'Added subscriber' : 'Added subscriber'
+ , 'is already subscribed' : 'is already subscribed'
+ , 'Comment' : 'Comment'
+ , 'Accept' : 'Accept'
+ , 'Resolve' : 'Resolve'
+ , 'Reject' : 'Reject'
+ , 'Defer' : 'Defer'
+ , 'followup' : 'followup'
+ }
+
+MAILTEMPLATES = { 'reply_template' : REPLY_TEMPLATE
+ , 'newissue_template' : NEW_ISSUE_TEMPLATE
+ , 'error_template' : MAIL_ERROR_TEMPLATE
+ }
+
class JTrackerBase(ExtensionClass.Base):
""" JTracker - A issue tracker """
security = ClassSecurityInfo()
meta_type = 'JTracker'
- _translations = { 'Pending' : 'Pending'
- , 'Accepted' : 'Accepted'
- , 'Deferred' : 'Deferred'
- , 'Rejected' : 'Rejected'
- , 'Resolved' : 'Resolved'
- , 'Missing values for' : 'Missing values for'
- , 'Invalid email address' : 'Invalid email address'
- , 'File size too large, limit is': 'File size too large, limit is'
- , 'Title' : 'Title'
- , 'Request type' : 'Request Type'
- , 'Component' : 'Component'
- , 'Description' : 'Description'
- , 'Requester Name' : 'Requester Name'
- , 'Requester Email' : 'Requester Email'
- }
+ _translations = {}
+ _mailtemplates = {}
_views = { 'index_html' : { 'view_label' : 'Default View'
, 'view_id' : 'index_html'
@@ -355,7 +372,28 @@ class JTrackerBase(ExtensionClass.Base):
security.declarePublic('getTranslations')
def getTranslations(self):
""" Retrieve the internal translations """
- return tuple(self._translations.items())
+ t_copy = TRANSLATIONS.copy()
+ t_copy.update(self._translations)
+
+ return tuple(t_copy.items())
+
+
+ security.declareProtected(ManageJTracker, 'getMailtemplates')
+ def getMailtemplates(self):
+ """ Retrieve the mail templates """
+ t_copy = MAILTEMPLATES.copy()
+ t_copy.update(self._mailtemplates)
+
+ return tuple(t_copy.items())
+
+
+ security.declarePrivate('getMailtemplateByName')
+ def getMailtemplateByName(self, template_name):
+ """ Get template text """
+ t_copy = MAILTEMPLATES.copy()
+ t_copy.update(self._mailtemplates)
+
+ return t_copy.get(template_name, '')
security.declareProtected(ManageJTracker, 'manage_updateTranslations')
@@ -365,16 +403,19 @@ class JTrackerBase(ExtensionClass.Base):
translations = REQUEST.form
current = self._translations
- current_keys = current.keys()
+ current_mailtemplates = self._mailtemplates
for key, val in translations.items():
- if key in current_keys:
+ if key in TRANSLATIONS.keys():
current[key] = val
+ elif key in MAILTEMPLATES.keys():
+ current_mailtemplates[key] = val
self._translations = current
+ self._mailtemplates = current_mailtemplates
if REQUEST is not None:
- msg = 'Transactions updated'
+ msg = 'Translations updated'
REQUEST.set('manage_tabs_message', msg)
return self.translationsForm(manage_tabs_message=msg)
@@ -463,17 +504,18 @@ class JTrackerBase(ExtensionClass.Base):
tracker_url = self.absolute_url()
issue_url = '%s/%s' % (tracker_url, id)
-
- msg = NEW_ISSUE_TEMPLATE % { 'requester_name' : requester_name
- , 'requester_email' : requester_email
- , 'component' : component
- , 'request_type' : request_type
- , 'request_url' : issue_url
- , 'title' : title
- , 'description' : description
- , 'jtracker_title' : self.title
- , 'jtracker_url' : tracker_url
- }
+ mailtemplate = self.getMailtemplateByName('newissue_template')
+
+ msg = mailtemplate % { 'requester_name' : requester_name
+ , 'requester_email' : requester_email
+ , 'component' : component
+ , 'request_type' : request_type
+ , 'request_url' : issue_url
+ , 'title' : title
+ , 'description' : description
+ , 'jtracker_title' : self.title
+ , 'jtracker_url' : tracker_url
+ }
jtracker_to = '"%s" <%s>' % (self.admin_name, self.admin_email)
requester_to = '"%s" <%s>' % (requester_name, requester_email)
subject = '%s %s: "%s" (%s)' % (component, request_type, title, id)
@@ -619,14 +661,15 @@ class JTrackerBase(ExtensionClass.Base):
, req_email
)
if errors:
- msg = MAIL_ERROR_TEMPLATE % { 'subject' : subject
- , 'description' : description
- , 'requester_name' : req_name
- , 'requester_email' : req_email
- , 'errors' : '\n'.join(errors)
- , 'jtracker_title' : self.title
- , 'jtracker_url' : self.absolute_url()
- }
+ mailtemplate = self.getMailtemplateByName('error_template')
+ msg = mailtemplate % { 'subject' : subject
+ , 'description' : description
+ , 'requester_name' : req_name
+ , 'requester_email' : req_email
+ , 'errors' : '\n'.join(errors)
+ , 'jtracker_title' : self.title
+ , 'jtracker_url' : self.absolute_url()
+ }
self.sendMail( '"%s" <%s>' % (self.admin_name, self.admin_email)
, 'Mail failure'
@@ -652,14 +695,15 @@ class JTrackerBase(ExtensionClass.Base):
, body
)
except:
- msg = MAIL_ERROR_TEMPLATE % { 'subject' : subject
- , 'description' : body
- , 'requester_name' : ''
- , 'requester_email' : to_addrs
- , 'errors' : str(sys.exc_info())
- , 'jtracker_title' : self.title
- , 'jtracker_url' : self.absolute_url()
- }
+ mailtemplate = self.getMailtemplateByName('error_template')
+ msg = mailtemplate % { 'subject' : subject
+ , 'description' : body
+ , 'requester_name' : ''
+ , 'requester_email' : to_addrs
+ , 'errors' : str(sys.exc_info())
+ , 'jtracker_title' : self.title
+ , 'jtracker_url' : self.absolute_url()
+ }
mh.simple_send( '"%s" <%s>' % (self.admin_name, self.admin_email)
, f
diff --git a/JTrackerIssue.py b/JTrackerIssue.py
index ab5f03a..a5ab55a 100644
--- a/JTrackerIssue.py
+++ b/JTrackerIssue.py
@@ -27,7 +27,6 @@ from AccessControl.SecurityManagement import getSecurityManager
# JTracker package imports
from Permissions import ManageJTracker, SubmitJTrackerIssues
from Permissions import SupportJTrackerIssues
-from utils import REPLY_TEMPLATE
_wwwdir = os.path.join(package_home(globals()), 'www')
addJTrackerIssueForm = PageTemplateFile('addJTrackerIssue.pt', _wwwdir)
@@ -419,27 +418,29 @@ class JTrackerIssue(PropertyManager, SimpleItem):
self.indexObject()
if send_email:
- jtracker = self.getTracker()
- jtracker_url = jtracker.absolute_url()
-
- msg = REPLY_TEMPLATE % { 'requester_name' : requester_name
- , 'requester_email' : requester_email
- , 'component' : self.component
- , 'request_type' : reply_type
- , 'request_url' : self.absolute_url()
- , 'title' : self.title
- , 'description' : description
- , 'jtracker_title' : jtracker.title
- , 'jtracker_url' : jtracker_url
- }
- subject = '%s followup: "%s" (%s)' % ( self.component
- , self.title
- , self.getId()
- )
+ jt = self.getTracker()
+ jt_url = jt.absolute_url()
+ mailtemplate = jt.getMailtemplateByName('reply_template')
+
+ msg = mailtemplate % { 'requester_name' : requester_name
+ , 'requester_email' : requester_email
+ , 'component' : self.component
+ , 'request_type' : jt.translate(reply_type)
+ , 'request_url' : self.absolute_url()
+ , 'title' : self.title
+ , 'description' : description
+ , 'jtracker_title' : jt.title
+ , 'jtracker_url' : jt_url
+ }
+ subject = '%s %s: "%s" (%s)' % ( self.component
+ , jt.translate('followup')
+ , self.title
+ , self.getId()
+ )
subscribers = filter(None, self.getProperty('subscribers') or ())
for subscriber in subscribers:
- jtracker.sendMail(subscriber, subject, msg)
+ jt.sendMail(subscriber, subject, msg)
if REQUEST is not None:
REQUEST.RESPONSE.redirect(self.absolute_url())
@@ -570,9 +571,7 @@ class JTrackerIssue(PropertyManager, SimpleItem):
security.declarePublic('manage_subscribe')
def manage_subscribe(self, email='', REQUEST=None):
""" Subscribe to this issue """
- if not email:
- msg = 'No email address specified'
- elif email.find('@') == -1 or email.find('.') == -1:
+ if not email or email.find('@') == -1 or email.find('.') == -1:
msg = 'Invalid email address'
else:
email = email.strip()
@@ -581,12 +580,13 @@ class JTrackerIssue(PropertyManager, SimpleItem):
subscribers = list(self.getProperty('subscribers', []))
subscribers.append(email)
self._updateProperty('subscribers', filter(None, subscribers))
- msg = 'Added subscriber "%s"' % email
+ msg = 'Added subscriber %s' % email
else:
- msg = '"%s" is already subscribed' % email
+ msg = '%s is already subscribed' % email
if REQUEST is not None:
- return self.index_html(err_msg=msg, REQUEST=REQUEST)
+ ret_url = '%s?error_msg=%s' % (self.absolute_url(), msg)
+ REQUEST.RESPONSE.redirect(ret_url)
security.declarePublic('followups')
diff --git a/www/translateJTracker.pt b/www/translateJTracker.pt
index db8f2e7..ffa4049 100644
--- a/www/translateJTracker.pt
+++ b/www/translateJTracker.pt
@@ -34,6 +34,18 @@
</td>
</tr>
+ <tr tal:repeat="mts here/getMailtemplates">
+ <td align="left" valign="top" class="form-label"
+ tal:content="python: mts[0]">
+ some_template
+ </td>
+ <td align="left" valign="top" class="form-text">
+ <textarea name="" rows="10" cols="45" nowrap="nowrap"
+ tal:attributes="name python: mts[0]"
+ tal:content="python: mts[1]"></textarea>
+ </td>
+ </tr>
+
<tr>
<td align="left" valign="top" colspan="2" class="form-element">
<input class="form-element" type="submit" name="submit"