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.

client.py 2.7 KiB

12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. from webnotes import _
  6. import webnotes.model
  7. import json
  8. @webnotes.whitelist()
  9. def get(doctype, name=None, filters=None):
  10. if filters and not name:
  11. name = webnotes.conn.get_value(doctype, json.loads(filters))
  12. if not name:
  13. raise Exception, "No document found for given filters"
  14. return [d.fields for d in webnotes.bean(doctype, name).doclist]
  15. @webnotes.whitelist()
  16. def get_value(doctype, fieldname, filters=None, as_dict=True, debug=False):
  17. if not webnotes.has_permission(doctype):
  18. webnotes.msgprint("No Permission", raise_exception=True)
  19. if fieldname and fieldname.startswith("["):
  20. fieldname = json.loads(fieldname)
  21. return webnotes.conn.get_value(doctype, json.loads(filters), fieldname, as_dict=as_dict, debug=debug)
  22. @webnotes.whitelist()
  23. def set_value(doctype, docname, fieldname, value):
  24. if fieldname in webnotes.model.default_fields:
  25. webnotes.throw(_("Cannot edit standard fields"))
  26. doc = webnotes.conn.get_value(doctype, docname, ["parenttype", "parent"], as_dict=True)
  27. if doc and doc.parent:
  28. bean = webnotes.bean(doc.parenttype, doc.parent)
  29. child = bean.doclist.getone({"doctype": doctype, "name": docname})
  30. child.fields[fieldname] = value
  31. else:
  32. bean = webnotes.bean(doctype, docname)
  33. bean.doc.fields[fieldname] = value
  34. bean.save()
  35. return [d.fields for d in bean.doclist]
  36. @webnotes.whitelist()
  37. def insert(doclist):
  38. if isinstance(doclist, basestring):
  39. doclist = json.loads(doclist)
  40. doclist[0]["__islocal"] = 1
  41. return save(doclist)
  42. @webnotes.whitelist()
  43. def save(doclist):
  44. if isinstance(doclist, basestring):
  45. doclist = json.loads(doclist)
  46. doclistobj = webnotes.bean(doclist)
  47. doclistobj.save()
  48. return [d.fields for d in doclist]
  49. @webnotes.whitelist()
  50. def submit(doclist):
  51. if isinstance(doclist, basestring):
  52. doclist = json.loads(doclist)
  53. doclistobj = webnotes.bean(doclist)
  54. doclistobj.submit()
  55. return [d.fields for d in doclist]
  56. @webnotes.whitelist()
  57. def cancel(doctype, name):
  58. wrapper = webnotes.bean(doctype, name)
  59. wrapper.cancel()
  60. return [d.fields for d in wrapper.doclist]
  61. @webnotes.whitelist()
  62. def delete(doctype, name):
  63. webnotes.delete_doc(doctype, name)
  64. @webnotes.whitelist()
  65. def set_default(key, value, parent=None):
  66. """set a user default value"""
  67. webnotes.conn.set_default(key, value, parent or webnotes.session.user)
  68. webnotes.clear_cache(user=webnotes.session.user)
  69. @webnotes.whitelist()
  70. def make_width_property_setter():
  71. doclist = json.loads(webnotes.form_dict.doclist)
  72. if doclist[0]["doctype"]=="Property Setter" and doclist[0]["property"]=="width":
  73. bean = webnotes.bean(doclist)
  74. bean.ignore_permissions = True
  75. bean.insert()