Merge remote-tracking branch 'jdshu/649_use_form_data_field'
[mediagoblin.git] / mediagoblin / user_pages / lib.py
CommitLineData
252eaf21
DM
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
17from mediagoblin.tools.mail import send_email
18from mediagoblin.tools.template import render_template
fa72e516 19from mediagoblin.tools.translate import pass_to_ugettext as _
252eaf21
DM
20from mediagoblin import mg_globals
21
00722c99 22
252eaf21
DM
23def send_comment_email(user, comment, media, request):
24 """
25 Sends comment email to user when a comment is made on their media.
26
27 Args:
28 - user: the user object to whom the email is sent
29 - comment: the comment object referencing user's media
30 - media: the media object the comment is about
31 - request: the request
32 """
33
fa72e516
DM
34 comment_url = request.urlgen(
35 'mediagoblin.user_pages.media_home.view_comment',
5c2b8486 36 comment=comment.id,
00722c99
JW
37 user=media.get_uploader.username,
38 media=media.slug_or_id,
39 qualified=True) + '#comment'
252eaf21 40
00722c99 41 comment_author = comment.get_author.username
252eaf21
DM
42
43 rendered_email = render_template(
44 request, 'mediagoblin/user_pages/comment_email.txt',
00722c99
JW
45 {'username': user.username,
46 'comment_author': comment_author,
47 'comment_content': comment.content,
48 'comment_url': comment_url})
252eaf21
DM
49
50 send_email(
51 mg_globals.app_config['email_sender_address'],
52 [user.email],
00722c99
JW
53 '{instance_title} - {comment_author} '.format(
54 comment_author=comment_author,
55 instance_title=mg_globals.app_config['html_title']) \
56 + _('commented on your post'),
252eaf21 57 rendered_email)