Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

47 wiersze
1.5 KiB

  1. import webnotes
  2. @webnotes.whitelist()
  3. def get_comments(doctype=None, docname=None, limit=5):
  4. """load last 5 comments"""
  5. nc, cl = 0, []
  6. if not doctype:
  7. doctype, docname, limit = webnotes.form_dict.get('dt'), webnotes.form_dict.get('dn'), \
  8. webnotes.form_dict.get('limit')
  9. nc = int(webnotes.conn.sql("""select count(*) from `tabComment Widget Record`
  10. where comment_doctype=%s and comment_docname=%s""", (doctype, docname))[0][0])
  11. if nc:
  12. cl = webnotes.conn.sql("""select comment, ifnull(comment_by_fullname, comment_by)
  13. AS 'comment_by_fullname', creation from `tabComment Widget Record`
  14. where comment_doctype=%s and comment_docname=%s
  15. order by creation desc limit %s""" % ('%s','%s',limit), (doctype, docname), as_dict=1)
  16. webnotes.response['n_comments'], webnotes.response['comment_list'] = nc, cl
  17. @webnotes.whitelist()
  18. def add_comment():
  19. """add a new comment"""
  20. import time
  21. args = webnotes.form_dict
  22. if args.get('comment'):
  23. from webnotes.model.doc import Document
  24. from webnotes.utils import nowdate
  25. cmt = Document('Comment Widget Record')
  26. for arg in ['comment', 'comment_by', 'comment_by_fullname', 'comment_doctype', \
  27. 'comment_docname']:
  28. cmt.fields[arg] = args[arg]
  29. cmt.save(1)
  30. import startup.event_handlers
  31. if hasattr(startup.event_handlers, 'comment_added'):
  32. startup.event_handlers.comment_added(cmt)
  33. @webnotes.whitelist()
  34. def remove_comment():
  35. """remove a comment"""
  36. args = webnotes.form_dict
  37. webnotes.conn.sql("delete from `tabComment Widget Record` where name=%s",args.get('id'))