Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

66 rindas
2.0 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import frappe
  5. def get_notification_config():
  6. return {
  7. "for_doctype": {
  8. "Scheduler Log": {"seen": 0},
  9. "Communication": {"status": "Open", "communication_type": "Communication"},
  10. "ToDo": "frappe.core.notifications.get_things_todo",
  11. "Event": "frappe.core.notifications.get_todays_events",
  12. "Error Snapshot": {"seen": 0, "parent_error_snapshot": None},
  13. },
  14. "for_other": {
  15. "Likes": "frappe.core.notifications.get_unseen_likes",
  16. "Chat": "frappe.core.notifications.get_unread_messages",
  17. }
  18. }
  19. def get_things_todo(as_list=False):
  20. """Returns a count of incomplete todos"""
  21. data = frappe.get_list("ToDo",
  22. fields=["name", "description"] if as_list else "count(*)",
  23. filters=[["ToDo", "status", "=", "Open"]],
  24. or_filters=[["ToDo", "owner", "=", frappe.session.user],
  25. ["ToDo", "assigned_by", "=", frappe.session.user]],
  26. as_list=True)
  27. if as_list:
  28. return data
  29. else:
  30. return data[0][0]
  31. def get_todays_events(as_list=False):
  32. """Returns a count of todays events in calendar"""
  33. from frappe.desk.doctype.event.event import get_events
  34. from frappe.utils import nowdate
  35. today = nowdate()
  36. events = get_events(today, today)
  37. return events if as_list else len(events)
  38. def get_unread_messages():
  39. "returns unread (docstatus-0 messages for a user)"
  40. return frappe.db.sql("""\
  41. SELECT count(*)
  42. FROM `tabCommunication`
  43. WHERE communication_type in ('Chat', 'Notification')
  44. AND reference_doctype = 'User'
  45. AND reference_name = %s
  46. and modified >= DATE_SUB(NOW(),INTERVAL 1 YEAR)
  47. AND seen=0
  48. """, (frappe.session.user,))[0][0]
  49. def get_unseen_likes():
  50. """Returns count of unseen likes"""
  51. return frappe.db.sql("""select count(*) from `tabCommunication`
  52. where
  53. communication_type='Comment'
  54. and modified >= DATE_SUB(NOW(),INTERVAL 1 YEAR)
  55. and comment_type='Like'
  56. and owner is not null and owner!=%(user)s
  57. and reference_owner=%(user)s
  58. and seen=0""", {"user": frappe.session.user})[0][0]