http.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #coding=utf-8
  2. """JSON helper functions"""
  3. import copy
  4. import traceback
  5. import sys
  6. import _thread
  7. from django.conf import settings
  8. from django.http import JsonResponse as DJR
  9. def JsonEditData(data=None):
  10. ret = {
  11. 'success': 1,
  12. 'url': data,
  13. 'message': 'success'
  14. }
  15. return DJR(ret, safe=False)
  16. def JsonData(data=None):
  17. return DJR(data, safe=False)
  18. def JsonResponse(data=None):
  19. ret = {
  20. 'code': 0,
  21. 'data': data,
  22. }
  23. return DJR(ret, safe=False)
  24. def JsonError(error_string):
  25. data = {
  26. 'code': 1,
  27. 'msg': error_string
  28. }
  29. return DJR(data, safe=False, json_dumps_params={'ensure_ascii':False})
  30. def ForbiddenResponse():
  31. data = {
  32. 'code': 1001,
  33. 'msg': u'拒绝访问',
  34. }
  35. return DJR(data, safe=False)
  36. def DataGridResponse(data, total, more=None):
  37. result = {
  38. 'code': 0,
  39. 'count':total,
  40. 'data': data
  41. }
  42. if more:
  43. result['more'] = more
  44. return DJR(result, safe=False)
  45. def EasyuiDataGridResponse(data, total):
  46. result = {
  47. 'total':total,
  48. 'rows': data,
  49. }
  50. return DJR(result, safe=False)
  51. # For backwards compatability purposes
  52. JSONResponse = JsonResponse
  53. JSONError = JsonError
  54. DataGridJSONResponse = DataGridResponse
  55. ForbiddenJSONResponse = ForbiddenResponse
  56. JsonData = JsonData
  57. JSONEditdata = JsonEditData