controls.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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-6-30 20:34:48 (CST)
  10. # By:
  11. # Description:
  12. # **************************************************************************
  13. from flask import url_for
  14. from flask_login import current_user
  15. from .models import db
  16. from .models import Notice
  17. def reply(topic, reply):
  18. url = url_for('topic.topic',
  19. uid=topic.uid,
  20. _anchor='reply-' + str(reply.id))
  21. notice = Notice()
  22. notice.category = 'reply'
  23. notice.content = {'url': url,
  24. 'content': reply.content[:100],
  25. 'title': topic.title}
  26. notice.rece_id = topic.author_id
  27. notice.send_user = current_user
  28. db.session.add(notice)
  29. db.session.commit()
  30. def collect(topic):
  31. url = url_for('topic.topic', uid=topic.uid)
  32. notice = Notice()
  33. notice.category = 'collect'
  34. notice.content = {'url': url, 'title': topic.title}
  35. notice.rece_id = topic.author_id
  36. notice.send_user = current_user
  37. db.session.add(notice)
  38. db.session.commit()
  39. def like(reply):
  40. topic = reply.topic
  41. url = url_for('topic.topic',
  42. uid=topic.uid,
  43. _anchor='reply-' + str(reply.id))
  44. notice = Notice()
  45. notice.category = 'like'
  46. notice.content = {'url': url,
  47. 'title': topic.title,
  48. 'content': reply.content[:100]}
  49. notice.rece_id = reply.author_id
  50. notice.send_user = current_user
  51. db.session.add(notice)
  52. db.session.commit()
  53. def user(userId):
  54. notice = Notice()
  55. notice.category = 'user'
  56. notice.rece_id = userId
  57. notice.send_user = current_user
  58. db.session.add(notice)
  59. db.session.commit()