launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #18982
[Merge] lp:~cjwatson/launchpad/consolidate-get-email-template into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/consolidate-get-email-template into lp:launchpad.
Commit message:
Use the common get_email_template helper rather than similar per-app versions.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/consolidate-get-email-template/+merge/264433
Use the common get_email_template helper rather than similar per-app versions.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/consolidate-get-email-template into lp:launchpad.
=== modified file 'lib/lp/answers/notification.py'
--- lib/lp/answers/notification.py 2012-01-01 02:58:52 +0000
+++ lib/lp/answers/notification.py 2015-07-10 15:37:45 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Notifications for the Answers system."""
@@ -8,8 +8,6 @@
'QuestionNotification',
]
-import os
-
from zope.component import getUtility
from lp.answers.enums import (
@@ -19,21 +17,12 @@
from lp.answers.interfaces.questionjob import IQuestionEmailJobSource
from lp.registry.interfaces.person import IPerson
from lp.services.config import config
+from lp.services.mail.helpers import get_email_template
from lp.services.mail.mailwrapper import MailWrapper
from lp.services.propertycache import cachedproperty
from lp.services.webapp.publisher import canonical_url
-def get_email_template(filename):
- """Returns the email template with the given file name.
-
- The templates are located in 'emailtemplates'.
- """
- base = os.path.dirname(__file__)
- fullpath = os.path.join(base, 'emailtemplates', filename)
- return open(fullpath).read()
-
-
class QuestionNotification:
"""Base class for a notification related to a question.
@@ -146,10 +135,11 @@
def unsupported_language_warning(self):
"""Warning about the fact that the question is written in an
unsupported language."""
- return get_email_template(
- 'question-unsupported-language-warning.txt') % {
- 'question_language': self.question.language.englishname,
- 'target_name': self.question.target.displayname}
+ template = get_email_template(
+ 'question-unsupported-language-warning.txt', app='answers')
+ return template % {
+ 'question_language': self.question.language.englishname,
+ 'target_name': self.question.target.displayname}
class QuestionAddedNotification(QuestionNotification):
@@ -167,7 +157,9 @@
def getBody(self):
"""See QuestionNotification."""
question = self.question
- body = get_email_template('question-added-notification.txt') % {
+ template = get_email_template(
+ 'question-added-notification.txt', app='answers')
+ body = template % {
'target_name': question.target.displayname,
'question_id': question.id,
'question_url': canonical_url(question),
@@ -311,7 +303,8 @@
replacements['body'] = body
- return get_email_template(self.body_template) % replacements
+ template = get_email_template(self.body_template, app='answers')
+ return template % replacements
# Header template used when a new message is added to the question.
action_header_template = {
@@ -407,8 +400,9 @@
def getBody(self):
"""See QuestionNotification."""
question = self.question
- return get_email_template(
- 'question-unsupported-languages-added.txt') % {
+ template = get_email_template(
+ 'question-unsupported-languages-added.txt', app='answers')
+ return template % {
'target_name': question.target.displayname,
'question_id': question.id,
'question_url': canonical_url(question),
=== modified file 'lib/lp/coop/answersbugs/notification.py'
--- lib/lp/coop/answersbugs/notification.py 2012-01-01 02:58:52 +0000
+++ lib/lp/coop/answersbugs/notification.py 2015-07-10 15:37:45 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Notifications related to linking bugs and questions."""
@@ -6,25 +6,14 @@
__metaclass__ = type
__all__ = []
-import os
-
from lazr.lifecycle.interfaces import IObjectModifiedEvent
from lp.answers.notification import QuestionNotification
from lp.bugs.interfaces.bugtask import IBugTask
+from lp.services.mail.helpers import get_email_template
from lp.services.webapp.publisher import canonical_url
-def get_email_template(filename):
- """Returns the email template with the given file name.
-
- The templates are located in 'emailtemplates'.
- """
- base = os.path.dirname(__file__)
- fullpath = os.path.join(base, 'emailtemplates', filename)
- return open(fullpath).read()
-
-
def dispatch_linked_question_notifications(bugtask, event):
"""Send notifications to linked question subscribers when the bugtask
status change.
@@ -58,14 +47,15 @@
def getBody(self):
"""See QuestionNotification."""
- return get_email_template(
- 'question-linked-bug-status-updated.txt') % {
- 'bugtask_target_name': self.bugtask.target.displayname,
- 'question_id': self.question.id,
- 'question_title': self.question.title,
- 'question_url': canonical_url(self.question),
- 'bugtask_url': canonical_url(self.bugtask),
- 'bug_id': self.bugtask.bug.id,
- 'bugtask_title': self.bugtask.bug.title,
- 'old_status': self.old_bugtask.status.title,
- 'new_status': self.bugtask.status.title}
+ template = get_email_template(
+ 'question-linked-bug-status-updated.txt', app='coop/answersbugs')
+ return template % {
+ 'bugtask_target_name': self.bugtask.target.displayname,
+ 'question_id': self.question.id,
+ 'question_title': self.question.title,
+ 'question_url': canonical_url(self.question),
+ 'bugtask_url': canonical_url(self.bugtask),
+ 'bug_id': self.bugtask.bug.id,
+ 'bugtask_title': self.bugtask.bug.title,
+ 'old_status': self.old_bugtask.status.title,
+ 'new_status': self.bugtask.status.title}
=== modified file 'lib/lp/registry/model/codeofconduct.py'
--- lib/lp/registry/model/codeofconduct.py 2015-07-08 16:05:11 +0000
+++ lib/lp/registry/model/codeofconduct.py 2015-07-10 15:37:45 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""A module for CodeOfConduct (CoC) related classes.
@@ -43,6 +43,7 @@
GPGVerificationError,
IGPGHandler,
)
+from lp.services.mail.helpers import get_email_template
from lp.services.mail.sendmail import (
format_address,
simple_sendmail,
@@ -210,8 +211,8 @@
def sendAdvertisementEmail(self, subject, content):
"""See ISignedCodeOfConduct."""
assert self.owner.preferredemail
- template = open('lib/lp/registry/emailtemplates/'
- 'signedcoc-acknowledge.txt').read()
+ template = get_email_template(
+ 'signedcoc-acknowledge.txt', app='registry')
fromaddress = format_address(
"Launchpad Code Of Conduct System",
config.canonical.noreply_from_address)
=== modified file 'lib/lp/services/mail/helpers.py'
--- lib/lp/services/mail/helpers.py 2013-08-12 03:12:44 +0000
+++ lib/lp/services/mail/helpers.py 2015-07-10 15:37:45 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
@@ -143,13 +143,14 @@
If the error message requires some parameters, those are given in
interpolation_items.
- The files are searched for in lib/lp.services/mail/errortemplates.
+ The files are searched for in lib/lp/services/mail/errortemplates.
"""
if error_templates is None:
error_templates = os.path.join(
os.path.dirname(__file__), 'errortemplates')
fullpath = os.path.join(error_templates, filename)
- error_template = open(fullpath).read()
+ with open(fullpath) as f:
+ error_template = f.read()
return error_template % interpolation_items
@@ -244,7 +245,8 @@
def get_email_template(filename, app=None):
"""Returns the email template with the given file name.
- The templates are located in 'lib/canonical/launchpad/emailtemplates'.
+ The templates are located in lib/lp/services/mail/emailtemplates or
+ lib/lp/<app>/emailtemplates.
"""
if app is None:
base = os.path.dirname(__file__)
@@ -253,7 +255,8 @@
import lp
base = os.path.dirname(lp.__file__)
fullpath = os.path.join(base, app, 'emailtemplates', filename)
- return open(fullpath).read()
+ with open(fullpath) as f:
+ return f.read()
def get_contact_email_addresses(person):
Follow ups