controls.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. # -*- coding=UTF-8 -*-
  3. # **************************************************************************
  4. # Copyright © 2016 jianglin
  5. # File Name: controls.py
  6. # Author: jianglin
  7. # Email: xiyang0807@gmail.com
  8. # Created: 2016-06-30 19:39:13 (CST)
  9. # Last Update:星期日 2016-7-24 17:16:21 (CST)
  10. # By:
  11. # Description:
  12. # **************************************************************************
  13. from flask import url_for
  14. from flask_login import current_user
  15. from maple.helpers import replies_page
  16. from .models import db
  17. from .models import Notice
  18. def reply(topic, reply):
  19. page = replies_page(topic.id)
  20. url = url_for('topic.topic',
  21. topicId=topic.uid,
  22. page=page,
  23. _anchor='reply' + str(reply.id))
  24. notice = Notice()
  25. notice.category = 'reply'
  26. notice.content = {'url': url,
  27. 'content': reply.content[:100],
  28. 'title': topic.title}
  29. notice.rece_id = topic.author_id
  30. notice.send_user = current_user
  31. db.session.add(notice)
  32. db.session.commit()
  33. def collect(topic):
  34. url = url_for('topic.topic', topicId=topic.uid)
  35. notice = Notice()
  36. notice.category = 'collect'
  37. notice.content = {'url': url, 'title': topic.title}
  38. notice.rece_id = topic.author_id
  39. notice.send_user = current_user
  40. db.session.add(notice)
  41. db.session.commit()
  42. def like(reply):
  43. topic = reply.topic
  44. url = url_for('topic.topic',
  45. topicId=topic.uid,
  46. _anchor='reply-' + str(reply.id))
  47. notice = Notice()
  48. notice.category = 'like'
  49. notice.content = {'url': url,
  50. 'title': topic.title,
  51. 'content': reply.content[:100]}
  52. notice.rece_id = reply.author_id
  53. notice.send_user = current_user
  54. db.session.add(notice)
  55. db.session.commit()
  56. def user(userId):
  57. notice = Notice()
  58. notice.category = 'user'
  59. notice.rece_id = userId
  60. notice.send_user = current_user
  61. db.session.add(notice)
  62. db.session.commit()