PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/handlers/module/community/CommunityForumSubscribe.py

https://gitlab.com/manoj-makkuboy/vikuit
Python | 61 lines | 35 code | 6 blank | 20 comment | 10 complexity | 3f9f0288600cfa066c76c2186369e866 MD5 | raw file
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. ##
  4. # (C) Copyright 2011 Jose Blanco <jose.blanco[a]vikuit.com>
  5. #
  6. # This file is part of "vikuit".
  7. #
  8. # "vikuit" is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # "vikuit" is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with "vikuit". If not, see <http://www.gnu.org/licenses/>.
  20. ##
  21. from google.appengine.ext import db
  22. from handlers.AuthenticatedHandler import *
  23. class CommunityForumSubscribe( AuthenticatedHandler ):
  24. def execute(self):
  25. key = self.get_param('key')#TODO if key is empty app crashed
  26. thread = model.Thread.get(key)
  27. memcache.delete(str(thread.key().id()) + '_thread')
  28. user = self.values['user']
  29. mail = user.email
  30. if not mail in thread.subscribers:
  31. if not self.auth():
  32. return
  33. thread.subscribers.append(user.email)
  34. thread.put()
  35. self.add_user_subscription(user, 'thread', thread.key().id())
  36. memcache.add(str(thread.key().id()) + '_thread', thread, 0)
  37. if self.get_param('x'):
  38. self.render_json({ 'action': 'subscribed' })
  39. else:
  40. self.redirect('/module/community.forum/%s' % thread.url_path)
  41. else:
  42. auth = self.get_param('auth')
  43. if not auth:
  44. self.values['thread'] = thread
  45. self.render('templates/module/community/community-forum-subscribe.html')
  46. else:
  47. if not self.auth():
  48. return
  49. thread.subscribers.remove(user.email)
  50. thread.put()
  51. self.remove_user_subscription(user, 'thread', thread.key().id())
  52. if self.get_param('x'):
  53. self.render_json({ 'action': 'unsubscribed' })
  54. else:
  55. self.redirect('/module/community.forum/%s' % thread.url_path)