You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 rivejä
2.9 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. import webnotes
  24. @webnotes.whitelist()
  25. def get_comments(doctype=None, docname=None, limit=5):
  26. """load last 5 comments"""
  27. nc, cl = 0, []
  28. if not doctype:
  29. doctype, docname, limit = webnotes.form_dict.get('dt'), webnotes.form_dict.get('dn'), \
  30. webnotes.form_dict.get('limit')
  31. nc = int(webnotes.conn.sql("""select count(*) from `tabComment`
  32. where comment_doctype=%s and comment_docname=%s""", (doctype, docname))[0][0])
  33. if nc:
  34. cl = webnotes.conn.sql("""select comment, ifnull(comment_by_fullname, comment_by)
  35. AS 'comment_by_fullname', creation from `tabComment`
  36. where comment_doctype=%s and comment_docname=%s
  37. order by creation desc limit %s""" % ('%s','%s',limit), (doctype, docname), as_dict=1)
  38. webnotes.response['n_comments'], webnotes.response['comment_list'] = nc, cl
  39. @webnotes.whitelist(allow_guest=True)
  40. def add_comment(args=None):
  41. """add a new comment"""
  42. import time
  43. if not args: args = webnotes.form_dict
  44. if webnotes.conn.sql("""select count(*) from tabComment where comment_doctype=%s
  45. and comment_docname=%s""", (args.comment_doctype, args.comment_docname))[0][0] >= 50:
  46. webnotes.msgprint("Max Comments reached!", raise_exception=True)
  47. if args.get('comment'):
  48. from webnotes.model.doc import Document
  49. cmt = Document('Comment')
  50. for arg in ['comment', 'comment_by', 'comment_by_fullname', 'comment_doctype', \
  51. 'comment_docname']:
  52. cmt.fields[arg] = args[arg]
  53. cmt.save(1)
  54. import startup.event_handlers
  55. if hasattr(startup.event_handlers, 'comment_added'):
  56. startup.event_handlers.comment_added(cmt)
  57. return cmt.fields
  58. @webnotes.whitelist()
  59. def remove_comment():
  60. """remove a comment"""
  61. args = webnotes.form_dict
  62. webnotes.conn.sql("delete from `tabComment` where name=%s",args.get('id'))