loglistview.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from django.db.models import Q
  2. from rest_framework.response import Response
  3. from rest_framework.views import APIView
  4. from django.http import HttpResponse
  5. from apps.log.models import Log
  6. class LogListView(APIView):
  7. # view log_list
  8. @staticmethod
  9. def get(request, *args, **kwargs):
  10. entity_class = request.GET.get('entity_class')
  11. action = request.GET.get('action')
  12. executor_username = request.GET.get('executor_username')
  13. executor_identify = request.GET.get('executor_identify')
  14. sort = request.GET.get('sort')
  15. dont_get = request.GET.get('dontGet')
  16. log_all = Log.objects.order_by('-create_time')
  17. if entity_class:
  18. log_all = log_all.filter(entity_class=entity_class)
  19. if action:
  20. log_all = log_all.filter(method=action)
  21. if executor_username:
  22. log_all = log_all.filter(executor_username=executor_username)
  23. if executor_identify:
  24. log_all = log_all.filter(executor_identify=executor_identify)
  25. if dont_get == '1':
  26. log_all = log_all.filter(~Q(method='GET'))
  27. if sort:
  28. log_all = log_all.order_by(sort)
  29. log_infos = []
  30. for log in log_all:
  31. log_infos.append({
  32. 'entity_class': log.entity_class,
  33. 'entity_name': log.entity_name,
  34. 'action': log.action,
  35. 'method': log.method,
  36. 'executor_id': log.executor_id,
  37. 'executor_username': log.executor_username,
  38. 'executor_identify': log.executor_identify,
  39. 'execute_time': log.create_time
  40. })
  41. return Response(log_infos)