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

13 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. import webnotes
  24. @webnotes.whitelist()
  25. def runserverobj():
  26. """
  27. Run server objects
  28. """
  29. import webnotes.model.code
  30. from webnotes.model.wrapper import ModelWrapper
  31. from webnotes.utils import cint
  32. doclist = None
  33. method = webnotes.form_dict.get('method')
  34. arg = webnotes.form_dict.get('arg')
  35. dt = webnotes.form_dict.get('doctype')
  36. dn = webnotes.form_dict.get('docname')
  37. if dt: # not called from a doctype (from a page)
  38. if not dn: dn = dt # single
  39. so = webnotes.model.code.get_obj(dt, dn)
  40. else:
  41. doclist = ModelWrapper()
  42. doclist.from_compressed(webnotes.form_dict.get('docs'), dn)
  43. so = doclist.make_obj()
  44. doclist.check_if_latest()
  45. check_guest_access(so.doc)
  46. if so:
  47. r = webnotes.model.code.run_server_obj(so, method, arg)
  48. if r:
  49. #build output as csv
  50. if cint(webnotes.form_dict.get('as_csv')):
  51. make_csv_output(r, so.doc.doctype)
  52. else:
  53. webnotes.response['message'] = r
  54. webnotes.response['docs'] =[so.doc] + so.doclist
  55. def check_guest_access(doc):
  56. if webnotes.session['user']=='Guest' and not webnotes.conn.sql("select name from tabDocPerm where role='Guest' and parent=%s and ifnull(`read`,0)=1", doc.doctype):
  57. webnotes.msgprint("Guest not allowed to call this object")
  58. raise Exception
  59. def make_csv_output(res, dt):
  60. """send method response as downloadable CSV file"""
  61. import webnotes
  62. from cStringIO import StringIO
  63. import csv
  64. f = StringIO()
  65. writer = csv.writer(f)
  66. for r in res:
  67. row = []
  68. for v in r:
  69. if isinstance(v, basestring):
  70. v = v.encode("utf-8")
  71. row.append(v)
  72. writer.writerow(row)
  73. f.seek(0)
  74. webnotes.response['result'] = unicode(f.read(), 'utf-8')
  75. webnotes.response['type'] = 'csv'
  76. webnotes.response['doctype'] = dt.replace(' ','')