FeedBackInfo.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. from django.views.generic.base import View
  2. from django.utils.decorators import method_decorator
  3. from django.views.decorators.csrf import csrf_exempt
  4. from Service.ModelService import ModelService
  5. from Model.models import Feedback_Info
  6. from django.utils import timezone
  7. import traceback
  8. from Object.ResponseObject import ResponseObject
  9. from Object.TokenObject import TokenObject
  10. from Service.CommonService import CommonService
  11. class FeedBackInfoView(View):
  12. def get(self, request, *args, **kwargs):
  13. request.encoding = 'utf-8'
  14. operation = kwargs.get('operation', None)
  15. return self.validation(request.GET, operation)
  16. def post(self, request, *args, **kwargs):
  17. request.encoding = 'utf-8'
  18. operation = kwargs.get('operation', None)
  19. return self.validation(request.POST, operation)
  20. def validation(self, request_dict, operation):
  21. response = ResponseObject()
  22. token = request_dict.get('token', None)
  23. tko = TokenObject(token)
  24. if operation == 'add':
  25. if tko.code == 0:
  26. return self.do_add(request_dict, response)
  27. else:
  28. return response.json(tko.code)
  29. else:
  30. return response.json(0, 414)
  31. def do_add(self, request_dict, response):
  32. return
  33. def add_info(self, request_dict, userID, response):
  34. content = request_dict.get('content', None)
  35. param_flag = CommonService.get_param_flag(data=[content])
  36. if param_flag is True:
  37. try:
  38. feedback_info = Feedback_Info(
  39. userID=userID,
  40. content=content,
  41. )
  42. feedback_info.save()
  43. except Exception:
  44. errorInfo = traceback.format_exc()
  45. print(errorInfo)
  46. return response.json(424, {'details': errorInfo})
  47. else:
  48. print(type(feedback_info.add_time))
  49. return response.json(0, {'id': feedback_info.id})
  50. return response.json(444)
  51. def query_info(self, request_dict, userID, response):
  52. page = int(request_dict.get('page', None))
  53. line = int(request_dict.get('line', None))
  54. param_flag = CommonService.get_param_flag(data=[page, line])
  55. if param_flag is True:
  56. feedback_info_queryset = Feedback_Info.objects.filter(userID=userID).order_by('-id')
  57. if feedback_info_queryset.exists():
  58. count = feedback_info_queryset.count()
  59. res = feedback_info_queryset[(page - 1) * line:page * line]
  60. send_json = CommonService.qs_to_dict(res)
  61. send_json['count'] = count
  62. return response.json(0, send_json)
  63. return response.json(0, {'datas': [], 'count': 0})
  64. else:
  65. return response.json(444)
  66. def update_info(self, request_dict, userID, response):
  67. content = request_dict.get('content', None)
  68. id = request_dict.get('id', None)
  69. param_flag = CommonService.get_param_flag(data=[id, content])
  70. if param_flag is True:
  71. try:
  72. feedback_info = Feedback_Info.objects.get(userID=userID, id=id)
  73. feedback_info.content = content
  74. feedback_info.save()
  75. except Exception as e:
  76. return response.json(10, {'details': repr(e)})
  77. else:
  78. now_time = timezone.localtime(timezone.now())
  79. return response.json(0, {'update_success': 1,
  80. 'update_time': str(now_time)})
  81. else:
  82. return response.json(444)
  83. def delete_info(self, request_dict, userID, response):
  84. id_list = request_dict.getlist('id', None)
  85. param_flag = CommonService.get_param_flag(data=[id_list])
  86. if param_flag is True:
  87. is_delete = Feedback_Info.objects.filter(id__in=id_list, userID=userID).delete()
  88. return response.json(0, {'delete_count': is_delete[0]})
  89. else:
  90. return response.json(444)
  91. def query_all_info(self, request_dict, userID, response):
  92. page = int(request_dict.get('page', None))
  93. line = int(request_dict.get('line', None))
  94. order = request_dict.get('order', '-id')
  95. status = request_dict.get('status', None)
  96. if order == '':
  97. order = '-id'
  98. param_flag = CommonService.get_param_flag(data=[page, line])
  99. if param_flag is True:
  100. check_perm = ModelService.check_perm(userID=userID, permID=30)
  101. if check_perm is True:
  102. if status is not None:
  103. feedback_info_queryset = Feedback_Info.objects.filter(status=status).order_by(order)
  104. else:
  105. feedback_info_queryset = Feedback_Info.objects.all().order_by(order)
  106. if feedback_info_queryset.exists():
  107. count = feedback_info_queryset.count()
  108. res = feedback_info_queryset[(page - 1) * line:page * line]
  109. send_json = CommonService.qs_to_dict(res)
  110. for k, v in enumerate(send_json["datas"]):
  111. username = ModelService.get_user_name(userID=send_json["datas"][k]['fields']['userID'])
  112. send_json["datas"][k]['fields']['username'] = username
  113. send_json['count'] = count
  114. return response.json(0, send_json)
  115. return response.json(0, {'datas': [], 'count': 0})
  116. else:
  117. return response.json(404)
  118. else:
  119. return response.json(444)
  120. def delete_by_admin(self, request_dict, userID, response):
  121. id_list = request_dict.getlist('id', None)
  122. param_flag = CommonService.get_param_flag(data=[id_list])
  123. if param_flag is True:
  124. check_perm = ModelService.check_perm(userID=userID, permID=10)
  125. if check_perm is True:
  126. is_delete = Feedback_Info.objects.filter(id__in=id_list).delete()
  127. return response.json(0, {'delete_count': is_delete[0]})
  128. else:
  129. return response.json(404)
  130. else:
  131. return response.json(444)
  132. def update_by_admin(self, request_dict, userID, response):
  133. id = request_dict.get('id', None)
  134. status = request_dict.get('status', None)
  135. param_flag = CommonService.get_param_flag(data=[id, status])
  136. if param_flag is True:
  137. check_perm = ModelService.check_perm(userID=userID, permID=50)
  138. if check_perm is True:
  139. try:
  140. feedback_info = Feedback_Info.objects.get(id=id)
  141. feedback_info.status = status
  142. feedback_info.save()
  143. except Exception as e:
  144. return response.json(302, {'details': repr(e)})
  145. else:
  146. now_time = timezone.localtime(timezone.now())
  147. return response.json(0, {'update_id': feedback_info.id, 'update_time': str(now_time)})
  148. else:
  149. return response.json(404)
  150. else:
  151. return response.json(444)