Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

76 Zeilen
2.0 KiB

  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. @webnotes.whitelist()
  7. def runserverobj():
  8. """
  9. Run server objects
  10. """
  11. import webnotes.model.code
  12. from webnotes.model.bean import Bean
  13. from webnotes.utils import cint
  14. wrapper = None
  15. method = webnotes.form_dict.get('method')
  16. arg = webnotes.form_dict.get('args', webnotes.form_dict.get("arg"))
  17. dt = webnotes.form_dict.get('doctype')
  18. dn = webnotes.form_dict.get('docname')
  19. webnotes.response["docs"] = []
  20. if dt: # not called from a doctype (from a page)
  21. if not dn: dn = dt # single
  22. so = webnotes.model.code.get_obj(dt, dn)
  23. else:
  24. bean = Bean()
  25. bean.from_compressed(webnotes.form_dict.get('docs'), dn)
  26. if not bean.has_read_perm():
  27. webnotes.msgprint(_("No Permission"), raise_exception = True)
  28. so = bean.make_controller()
  29. bean.check_if_latest(method="runserverobj")
  30. check_guest_access(so.doc)
  31. if so:
  32. r = webnotes.model.code.run_server_obj(so, method, arg)
  33. if r:
  34. #build output as csv
  35. if cint(webnotes.form_dict.get('as_csv')):
  36. make_csv_output(r, so.doc.doctype)
  37. else:
  38. webnotes.response['message'] = r
  39. webnotes.response['docs'] += so.doclist
  40. def check_guest_access(doc):
  41. 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):
  42. webnotes.msgprint("Guest not allowed to call this object")
  43. raise Exception
  44. def make_csv_output(res, dt):
  45. """send method response as downloadable CSV file"""
  46. import webnotes
  47. from cStringIO import StringIO
  48. import csv
  49. f = StringIO()
  50. writer = csv.writer(f)
  51. for r in res:
  52. row = []
  53. for v in r:
  54. if isinstance(v, basestring):
  55. v = v.encode("utf-8")
  56. row.append(v)
  57. writer.writerow(row)
  58. f.seek(0)
  59. webnotes.response['result'] = unicode(f.read(), 'utf-8')
  60. webnotes.response['type'] = 'csv'
  61. webnotes.response['doctype'] = dt.replace(' ','')