from django.db.models import Q from rest_framework.response import Response from rest_framework.views import APIView from django.http import HttpResponse from apps.log.models import Log class LogListView(APIView): # view log_list @staticmethod def get(request, *args, **kwargs): entity_class = request.GET.get('entity_class') action = request.GET.get('action') executor_username = request.GET.get('executor_username') executor_identify = request.GET.get('executor_identify') sort = request.GET.get('sort') dont_get = request.GET.get('dontGet') log_all = Log.objects.order_by('-create_time') if entity_class: log_all = log_all.filter(entity_class=entity_class) if action: log_all = log_all.filter(method=action) if executor_username: log_all = log_all.filter(executor_username=executor_username) if executor_identify: log_all = log_all.filter(executor_identify=executor_identify) if dont_get == '1': log_all = log_all.filter(~Q(method='GET')) if sort: log_all = log_all.order_by(sort) log_infos = [] for log in log_all: log_infos.append({ 'entity_class': log.entity_class, 'entity_name': log.entity_name, 'action': log.action, 'method': log.method, 'executor_id': log.executor_id, 'executor_username': log.executor_username, 'executor_identify': log.executor_identify, 'execute_time': log.create_time }) return Response(log_infos)