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.
 
 
 
 
 
 

111 lines
2.9 KiB

  1. import webnotes
  2. import webnotes.model.doc
  3. @webnotes.whitelist()
  4. def getdoc():
  5. """
  6. Loads a doclist for a given document. This method is called directly from the client.
  7. Requries "doctype", "name" as form variables.
  8. Will also call the "onload" method on the document.
  9. """
  10. import webnotes
  11. from webnotes.utils import cint
  12. form = webnotes.form_dict
  13. doctype, docname = form.get('doctype'), form.get('name')
  14. prefix = cint(form.get('from_archive')) and 'arc' or 'tab'
  15. if not (doctype and docname):
  16. raise Exception, 'doctype and name required!'
  17. doclist = []
  18. # single
  19. doclist = load_single_doc(doctype, docname, (form.get('user') or webnotes.session['user']), prefix)
  20. # load doctype along with the doc
  21. if form.get('getdoctype'):
  22. import webnotes.model.doctype
  23. doclist += webnotes.model.doctype.get(doctype)
  24. # tag as archived
  25. if prefix == 'arc':
  26. doclist[0].__archived=1
  27. webnotes.response['docs'] = doclist
  28. @webnotes.whitelist()
  29. def getdoctype():
  30. """load doctype"""
  31. import webnotes.model.doctype
  32. import webnotes.model.meta
  33. form, doclist = webnotes.form, []
  34. dt = form.getvalue('doctype')
  35. with_parent = form.getvalue('with_parent')
  36. # with parent (called from report builder)
  37. if with_parent:
  38. parent_dt = webnotes.model.meta.get_parent_dt(dt)
  39. if parent_dt:
  40. doclist = webnotes.model.doctype.get(parent_dt)
  41. webnotes.response['parent_dt'] = parent_dt
  42. if not doclist:
  43. doclist = webnotes.model.doctype.get(dt)
  44. # if single, send the record too
  45. if doclist[0].issingle:
  46. doclist += webnotes.model.doc.get(dt)
  47. # load search criteria for reports (all)
  48. doclist +=get_search_criteria(dt)
  49. webnotes.response['docs'] = doclist
  50. def load_single_doc(dt, dn, user, prefix):
  51. """load doc and call onload methods"""
  52. import webnotes.model.code
  53. if not dn: dn = dt
  54. dl = webnotes.model.doc.get(dt, dn, prefix=prefix)
  55. # archive, done
  56. if prefix=='arc':
  57. return dl
  58. try:
  59. so, r = webnotes.model.code.get_server_obj(dl[0], dl), None
  60. if hasattr(so, 'onload'):
  61. r = webnotes.model.code.run_server_obj(so, 'onload')
  62. if hasattr(so, 'custom_onload'):
  63. r = webnotes.model.code.run_server_obj(so, 'custom_onload')
  64. if r:
  65. webnotes.msgprint(r)
  66. except Exception, e:
  67. webnotes.errprint(webnotes.utils.getTraceback())
  68. webnotes.msgprint('Error in script while loading')
  69. raise e
  70. if dl and not dn.startswith('_'):
  71. webnotes.user.update_recent(dt, dn)
  72. # load search criteria ---- if doctype
  73. if dt=='DocType':
  74. dl += get_search_criteria(dt)
  75. return dl
  76. def get_search_criteria(dt):
  77. """bundle search criteria with doctype"""
  78. import webnotes.model.doc
  79. # load search criteria for reports (all)
  80. dl = []
  81. sc_list = webnotes.conn.sql("select name from `tabSearch Criteria` where doc_type = '%s' or parent_doc_type = '%s' and (disabled!=1 OR disabled IS NULL)" % (dt, dt))
  82. for sc in sc_list:
  83. if sc[0]:
  84. dl += webnotes.model.doc.get('Search Criteria', sc[0])
  85. return dl