tools.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. from mediagoblin.tools.template import render_template
  17. from mediagoblin.tools.translate import pass_to_ugettext as _
  18. from mediagoblin import mg_globals
  19. def generate_comment_message(user, comment, media, request):
  20. """
  21. Sends comment email to user when a comment is made on their media.
  22. Args:
  23. - user: the user object to whom the email is sent
  24. - comment: the comment object referencing user's media
  25. - media: the media object the comment is about
  26. - request: the request
  27. """
  28. comment_url = request.urlgen(
  29. 'mediagoblin.user_pages.media_home.view_comment',
  30. comment=comment.id,
  31. user=media.get_actor.username,
  32. media=media.slug_or_id,
  33. qualified=True) + '#comment'
  34. comment_author = comment.get_actor.username
  35. rendered_email = render_template(
  36. request, 'mediagoblin/user_pages/comment_email.txt',
  37. {'username': user.username,
  38. 'comment_author': comment_author,
  39. 'comment_content': comment.content,
  40. 'comment_url': comment_url})
  41. return {
  42. 'from': mg_globals.app_config['email_sender_address'],
  43. 'to': user.email,
  44. 'subject': '{instance_title} - {comment_author} '.format(
  45. comment_author=comment_author,
  46. instance_title=mg_globals.app_config['html_title']) \
  47. + _('commented on your post'),
  48. 'body': rendered_email}