Comment changes for federation
[mediagoblin.git] / mediagoblin / notifications / tools.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 from mediagoblin.tools.template import render_template
18 from mediagoblin.tools.translate import pass_to_ugettext as _
19 from mediagoblin import mg_globals
20
21 def generate_comment_message(user, comment, media, request):
22 """
23 Sends comment email to user when a comment is made on their media.
24
25 Args:
26 - user: the user object to whom the email is sent
27 - comment: the comment object referencing user's media
28 - media: the media object the comment is about
29 - request: the request
30 """
31
32 comment_url = request.urlgen(
33 'mediagoblin.user_pages.media_home.view_comment',
34 comment=comment.id,
35 user=media.get_actor.username,
36 media=media.slug_or_id,
37 qualified=True) + '#comment'
38
39 comment_author = comment.get_actor.username
40
41 rendered_email = render_template(
42 request, 'mediagoblin/user_pages/comment_email.txt',
43 {'username': user.username,
44 'comment_author': comment_author,
45 'comment_content': comment.content,
46 'comment_url': comment_url})
47
48 return {
49 'from': mg_globals.app_config['email_sender_address'],
50 'to': user.email,
51 'subject': '{instance_title} - {comment_author} '.format(
52 comment_author=comment_author,
53 instance_title=mg_globals.app_config['html_title']) \
54 + _('commented on your post'),
55 'body': rendered_email}