views.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.response import redirect
  17. from mediagoblin.tools.translate import pass_to_ugettext as _
  18. from mediagoblin.decorators import get_user_media_entry, require_active_login
  19. from mediagoblin import messages
  20. from mediagoblin.notifications import (add_comment_subscription,
  21. silence_comment_subscription, mark_comment_notification_seen,
  22. get_notifications)
  23. @get_user_media_entry
  24. @require_active_login
  25. def subscribe_comments(request, media):
  26. add_comment_subscription(request.user, media)
  27. messages.add_message(request,
  28. messages.SUCCESS,
  29. _('Subscribed to comments on %s!')
  30. % media.title)
  31. return redirect(request, location=media.url_for_self(request.urlgen))
  32. @get_user_media_entry
  33. @require_active_login
  34. def silence_comments(request, media):
  35. silence_comment_subscription(request.user, media)
  36. messages.add_message(request,
  37. messages.SUCCESS,
  38. _('You will not receive notifications for comments on'
  39. ' %s.') % media.title)
  40. return redirect(request, location=media.url_for_self(request.urlgen))
  41. @require_active_login
  42. def mark_all_comment_notifications_seen(request):
  43. """
  44. Marks all comment notifications seen.
  45. """
  46. for comment in get_notifications(request.user.id):
  47. mark_comment_notification_seen(comment.subject_id, request.user)
  48. if request.GET.get('next'):
  49. return redirect(request, location=request.GET.get('next'))
  50. else:
  51. return redirect(request, 'index')