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.

преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. from webnotes import _
  25. @webnotes.whitelist()
  26. def runserverobj():
  27. """
  28. Run server objects
  29. """
  30. import webnotes.model.code
  31. from webnotes.model.wrapper import ModelWrapper
  32. from webnotes.utils import cint
  33. wrapper = None
  34. method = webnotes.form_dict.get('method')
  35. arg = webnotes.form_dict.get('arg')
  36. dt = webnotes.form_dict.get('doctype')
  37. dn = webnotes.form_dict.get('docname')
  38. if dt: # not called from a doctype (from a page)
  39. if not dn: dn = dt # single
  40. so = webnotes.model.code.get_obj(dt, dn)
  41. else:
  42. wrapper = ModelWrapper()
  43. wrapper.from_compressed(webnotes.form_dict.get('docs'), dn)
  44. if not wrapper.has_read_perm():
  45. webnotes.msgprint(_("No Permission"), raise_exception = True)
  46. so = wrapper.make_obj()
  47. wrapper.check_if_latest()
  48. check_guest_access(so.doc)
  49. if so:
  50. r = webnotes.model.code.run_server_obj(so, method, arg)
  51. if r:
  52. #build output as csv
  53. if cint(webnotes.form_dict.get('as_csv')):
  54. make_csv_output(r, so.doc.doctype)
  55. else:
  56. webnotes.response['message'] = r
  57. webnotes.response['docs'] = so.doclist
  58. def check_guest_access(doc):
  59. 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):
  60. webnotes.msgprint("Guest not allowed to call this object")
  61. raise Exception
  62. def make_csv_output(res, dt):
  63. """send method response as downloadable CSV file"""
  64. import webnotes
  65. from cStringIO import StringIO
  66. import csv
  67. f = StringIO()
  68. writer = csv.writer(f)
  69. for r in res:
  70. row = []
  71. for v in r:
  72. if isinstance(v, basestring):
  73. v = v.encode("utf-8")
  74. row.append(v)
  75. writer.writerow(row)
  76. f.seek(0)
  77. webnotes.response['result'] = unicode(f.read(), 'utf-8')
  78. webnotes.response['type'] = 'csv'
  79. webnotes.response['doctype'] = dt.replace(' ','')