Example #1
0
def aggregator_case_record_get(request):
    logs = AggregatorCaseRecord.objects.all()
    offset = safe_int(request.query_params.get('offset', 0))
    limit = safe_int(request.query_params.get('limit', 15))
    limit = get_limit(limit)

    module = request.query_params.get('module')
    action_flag = request.query_params.get('action_flag')
    key = request.query_params.get('key')
    platform = request.query_params.get('platform')
    start_time = request.query_params.get('start_time')
    end_time = request.query_params.get('end_time')

    if module:
        logs = logs.filter(module=module)
    if key:
        logs = logs.filter(key=key)
    if platform:
        logs = logs.filter(platform=platform)
    if action_flag:
        logs = logs.filter(action_flag=action_flag)
    if start_time and end_time:
        start_time += ' 00:00:00'
        end_time += ' 23:59:59'
        logs = logs.filter(create_time__gte=start_time).filter(
            create_time__lte=end_time)

    total = logs.count()
    logs = logs.order_by('-create_time')[offset:offset + limit]

    serializer = AggregatorCaseRecordSerializer(logs, many=True)

    # extras转为dict
    for data in serializer.data:
        if check_json_format(data['extras']):
            data['extras'] = json.loads(data['extras'])
        data['create_time'] = time.mktime(
            time.strptime(data['create_time'], '%Y-%m-%dT%H:%M:%S.%f'))

    response = APIResponse(success=True, data=serializer.data)
    # 分页数据
    response[CONTENT_RANGE] = '{0}-{1}'.format(offset, offset + len(logs))
    response[CONTENT_TOTAL] = total
    return response
Example #2
0
    def get(self, request):
        logs = ExportRecord.objects.all()
        offset = safe_int(request.query_params.get('offset', 0))
        limit = safe_int(request.query_params.get('limit', 15))
        limit = get_limit(limit)

        file_name = request.query_params.get('file_name')
        status = request.query_params.get('status')
        operator_name = request.query_params.get('operator_name')
        start_time = request.query_params.get('start_time')
        end_time = request.query_params.get('end_time')

        if file_name:
            logs = logs.filter(file_name=file_name)
        if status:
            logs = logs.filter(status=status)
        if operator_name:
            logs = logs.filter(operator_name=operator_name)
        if start_time and end_time:
            start_time += ' 00:00:00'
            end_time += ' 23:59:59'
            logs = logs.filter(create_time__gte=start_time).filter(
                create_time__lte=end_time)

        total = logs.count()
        logs = logs.order_by('-create_time')[offset:offset + limit]

        serializer = ExportRecordSerializer(logs, many=True)

        # extras转为dict
        for data in serializer.data:
            if check_json_format(data['extras']):
                data['extras'] = json.loads(data['extras'])
            data['create_time'] = time.mktime(
                time.strptime(data['create_time'], '%Y-%m-%dT%H:%M:%S.%f'))

        response = APIResponse(success=True, data=serializer.data)
        # 分页数据
        response[CONTENT_RANGE] = '{0}-{1}'.format(offset, offset + len(logs))
        response[CONTENT_TOTAL] = total
        return response