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.
 
 
 
 
 
 

46 lines
1.5 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. # Event
  4. # -------------
  5. from __future__ import unicode_literals
  6. import frappe
  7. @frappe.whitelist()
  8. def get_cal_events(m_st, m_end):
  9. import frappe.model.doc
  10. # load owned events
  11. res1 = frappe.db.sql("""select name from `tabEvent`
  12. WHERE ifnull(event_date,'2000-01-01') between %s and %s and owner = %s
  13. and event_type != 'Public' and event_type != 'Cancel'""",
  14. (m_st, m_end, frappe.user.name))
  15. # load individual events
  16. res2 = frappe.db.sql("""select t1.name from `tabEvent` t1, `tabEvent User` t2
  17. where ifnull(t1.event_date,'2000-01-01') between %s and %s and t2.person = %s
  18. and t1.name = t2.parent and t1.event_type != 'Cancel'""",
  19. (m_st, m_end, frappe.user.name))
  20. # load role events
  21. roles = frappe.user.get_roles()
  22. myroles = ['t2.role = "%s"' % r.replace('"', '\"') for r in roles]
  23. myroles = '(' + (' OR '.join(myroles)) + ')'
  24. res3 = frappe.db.sql("""select t1.name from `tabEvent` t1, `tabEvent Role` t2
  25. where ifnull(t1.event_date,'2000-01-01') between %s and %s
  26. and t1.name = t2.parent and t1.event_type != 'Cancel' and %s""" %
  27. ('%s', '%s', myroles), (m_st, m_end))
  28. # load public events
  29. res4 = frappe.db.sql("select name from `tabEvent` \
  30. where ifnull(event_date,'2000-01-01') between %s and %s and event_type='Public'",
  31. (m_st, m_end))
  32. doclist, rl = [], []
  33. for r in res1 + res2 + res3 + res4:
  34. if not r in rl:
  35. doclist += frappe.model.doc.get('Event', r[0])
  36. rl.append(r)
  37. return doclist