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.

assign_to.py 2.8 KiB

13 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. """assign/unassign to ToDo"""
  2. import webnotes
  3. @webnotes.whitelist()
  4. def get():
  5. """get assigned to"""
  6. return webnotes.conn.sql("""select owner from `tabToDo Item`
  7. where reference_type=%(doctype)s and reference_name=%(name)s
  8. order by modified desc limit 5""", webnotes.form_dict, as_dict=1)
  9. @webnotes.whitelist()
  10. def add():
  11. """add in someone's to do list"""
  12. if webnotes.conn.sql("""select owner from `tabToDo Item`
  13. where reference_type=%(doctype)s and reference_name=%(name)s
  14. and owner=%(assign_to)s""", webnotes.form_dict):
  15. webnotes.msgprint("Already in todo")
  16. return
  17. else:
  18. from webnotes.model.doc import Document
  19. from webnotes.utils import nowdate
  20. d = Document("ToDo Item")
  21. d.owner = webnotes.form_dict['assign_to']
  22. d.reference_type = webnotes.form_dict['doctype']
  23. d.reference_name = webnotes.form_dict['name']
  24. d.description = webnotes.form_dict['description']
  25. d.priority = webnotes.form_dict.get('priority', 'Medium')
  26. d.date = webnotes.form_dict.get('date', nowdate())
  27. d.assigned_by = webnotes.user.name
  28. d.save(1)
  29. # notify
  30. notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', notify=webnotes.form_dict.get('notify'))
  31. # update feeed
  32. try:
  33. import home
  34. from webnotes.utils import get_full_name
  35. home.make_feed('Assignment', d.reference_type, d.reference_name, webnotes.session['user'],
  36. '[%s] Assigned to %s' % (d.priority, get_full_name(d.owner)), '#C78F58')
  37. except ImportError, e:
  38. pass
  39. return get()
  40. @webnotes.whitelist()
  41. def remove():
  42. """remove from todo"""
  43. res = webnotes.conn.sql("""\
  44. select assigned_by, owner, reference_type, reference_name from `tabToDo Item`
  45. where reference_type=%(doctype)s and reference_name=%(name)s
  46. and owner=%(assign_to)s""", webnotes.form_dict)
  47. webnotes.conn.sql("""delete from `tabToDo Item`
  48. where reference_type=%(doctype)s and reference_name=%(name)s
  49. and owner=%(assign_to)s""", webnotes.form_dict)
  50. if res and res[0]: notify_assignment(res[0][0], res[0][1], res[0][2], res[0][3])
  51. return get()
  52. def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', notify=0):
  53. """
  54. Notify assignee that there is a change in assignment
  55. """
  56. if not (assigned_by and owner and doc_type and doc_name): return
  57. # Search for email address in description -- i.e. assignee
  58. assignment = """<a href="#!Form/%s/%s">%s</a>""" % (doc_type, doc_name, doc_name)
  59. if action=='CLOSE':
  60. arg = {
  61. 'uid': assigned_by,
  62. 'comment': "The task %s, assigned to %s, has been closed by %s" % (assignment, owner, webnotes.user.name)
  63. }
  64. else:
  65. arg = {
  66. 'uid': owner,
  67. 'comment': "A new task, %s, has been assigned to you by %s" % (assignment, webnotes.user.name),
  68. 'notify': notify
  69. }
  70. from home.page.my_company import my_company
  71. my_company.post_comment(arg)