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.
 
 
 
 
 
 

63 lines
1.4 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import webnotes
  5. @webnotes.whitelist()
  6. def get():
  7. try:
  8. from startup.open_count import for_doctype, for_module
  9. except ImportError, e:
  10. return {}
  11. can_read = webnotes.user.get_can_read()
  12. open_count_doctype = {}
  13. open_count_module = {}
  14. for d in for_doctype:
  15. if d in can_read:
  16. condition = for_doctype[d]
  17. key = condition.keys()[0]
  18. result = webnotes.get_list(d, fields=["count(*)"],
  19. filters=[[d, key, "=", condition[key]]], as_list=True)[0][0]
  20. if result:
  21. open_count_doctype[d] = result
  22. for m in for_module:
  23. open_count_module[m] = for_module[m]()
  24. return {
  25. "open_count_doctype": open_count_doctype,
  26. "open_count_module": open_count_module
  27. }
  28. def get_notification_info_for_boot():
  29. out = get()
  30. can_read = webnotes.user.get_can_read()
  31. conditions = {}
  32. module_doctypes = {}
  33. doctype_info = dict(webnotes.conn.sql("""select name, module from tabDocType"""))
  34. try:
  35. from startup.open_count import for_doctype
  36. except ImportError:
  37. for_doctype = {}
  38. for d in list(set(can_read + for_doctype.keys())):
  39. if d in for_doctype:
  40. conditions[d] = for_doctype[d]
  41. if d in doctype_info:
  42. module_doctypes.setdefault(doctype_info[d], []).append(d)
  43. out.update({
  44. "conditions": conditions,
  45. "module_doctypes": module_doctypes,
  46. })
  47. return out