Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12 роки тому
11 роки тому
12 роки тому
12 роки тому
12 роки тому
11 роки тому
12 роки тому
12 роки тому
12 роки тому
11 роки тому
11 роки тому
12 роки тому
12 роки тому
12 роки тому
11 роки тому
11 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import webnotes
  5. from webnotes import _
  6. import webnotes.model
  7. import webnotes.utils
  8. import json, os
  9. @webnotes.whitelist()
  10. def get(doctype, name=None, filters=None):
  11. if filters and not name:
  12. name = webnotes.conn.get_value(doctype, json.loads(filters))
  13. if not name:
  14. raise Exception, "No document found for given filters"
  15. return [d.fields for d in webnotes.bean(doctype, name).doclist]
  16. @webnotes.whitelist()
  17. def get_value(doctype, fieldname, filters=None, as_dict=True, debug=False):
  18. if not webnotes.has_permission(doctype):
  19. webnotes.msgprint("No Permission", raise_exception=True)
  20. if fieldname and fieldname.startswith("["):
  21. fieldname = json.loads(fieldname)
  22. return webnotes.conn.get_value(doctype, json.loads(filters), fieldname, as_dict=as_dict, debug=debug)
  23. @webnotes.whitelist()
  24. def set_value(doctype, name, fieldname, value):
  25. if fieldname in webnotes.model.default_fields:
  26. webnotes.throw(_("Cannot edit standard fields"))
  27. doc = webnotes.conn.get_value(doctype, name, ["parenttype", "parent"], as_dict=True)
  28. if doc and doc.parent:
  29. bean = webnotes.bean(doc.parenttype, doc.parent)
  30. child = bean.doclist.getone({"doctype": doctype, "name": name})
  31. child.fields[fieldname] = value
  32. else:
  33. bean = webnotes.bean(doctype, name)
  34. bean.doc.fields[fieldname] = value
  35. bean.save()
  36. return [d.fields for d in bean.doclist]
  37. @webnotes.whitelist()
  38. def insert(doclist):
  39. if isinstance(doclist, basestring):
  40. doclist = json.loads(doclist)
  41. doclist[0]["__islocal"] = 1
  42. return save(doclist)
  43. @webnotes.whitelist()
  44. def save(doclist):
  45. if isinstance(doclist, basestring):
  46. doclist = json.loads(doclist)
  47. doclistobj = webnotes.bean(doclist)
  48. doclistobj.save()
  49. return [d.fields for d in doclist]
  50. @webnotes.whitelist()
  51. def rename_doc(doctype, old_name, new_name, merge=False):
  52. new_name = webnotes.rename_doc(doctype, old_name, new_name, merge=merge)
  53. return new_name
  54. @webnotes.whitelist()
  55. def submit(doclist):
  56. if isinstance(doclist, basestring):
  57. doclist = json.loads(doclist)
  58. doclistobj = webnotes.bean(doclist)
  59. doclistobj.submit()
  60. return [d.fields for d in doclist]
  61. @webnotes.whitelist()
  62. def cancel(doctype, name):
  63. wrapper = webnotes.bean(doctype, name)
  64. wrapper.cancel()
  65. return [d.fields for d in wrapper.doclist]
  66. @webnotes.whitelist()
  67. def delete(doctype, name):
  68. webnotes.delete_doc(doctype, name)
  69. @webnotes.whitelist()
  70. def set_default(key, value, parent=None):
  71. """set a user default value"""
  72. webnotes.conn.set_default(key, value, parent or webnotes.session.user)
  73. webnotes.clear_cache(user=webnotes.session.user)
  74. @webnotes.whitelist()
  75. def make_width_property_setter():
  76. doclist = json.loads(webnotes.form_dict.doclist)
  77. if doclist[0]["doctype"]=="Property Setter" and doclist[0]["property"]=="width":
  78. bean = webnotes.bean(doclist)
  79. bean.ignore_permissions = True
  80. bean.insert()
  81. @webnotes.whitelist()
  82. def bulk_update(docs):
  83. docs = json.loads(docs)
  84. failed_docs = []
  85. for doc in docs:
  86. try:
  87. ddoc = {key: val for key, val in doc.iteritems() if key not in ['doctype', 'docname']}
  88. doctype = doc['doctype']
  89. docname = doc['docname']
  90. bean = webnotes.bean(doctype, docname)
  91. bean.doc.update(ddoc)
  92. bean.save()
  93. except:
  94. failed_docs.append({
  95. 'doc': doc,
  96. 'exc': webnotes.utils.get_traceback()
  97. })
  98. return {'failed_docs': failed_docs}
  99. @webnotes.whitelist()
  100. def has_permission(doctype, docname, perm_type="read"):
  101. # perm_type can be one of read, write, create, submit, cancel, report
  102. return {"has_permission": webnotes.has_permission(doctype, perm_type.lower(), docname)}
  103. @webnotes.whitelist()
  104. def get_js(src):
  105. contentpath = os.path.join(webnotes.local.sites_path, src)
  106. with open(contentpath, "r") as srcfile:
  107. code = srcfile.read()
  108. if webnotes.local.lang != "en":
  109. code += "\n\n$.extend(wn._messages, {})".format(json.dumps(\
  110. webnotes.get_lang_dict("jsfile", contentpath)))
  111. return code