jumpserver/apps/audits/serializers.py

35 lines
1023 B
Python
Raw Normal View History

2016-10-08 16:12:18 +00:00
# -*- coding: utf-8 -*-
2016-10-20 11:01:57 +00:00
#
from __future__ import absolute_import, unicode_literals
2016-10-08 16:12:18 +00:00
from rest_framework import serializers
2016-10-26 11:10:14 +00:00
from common.utils import timesince
2016-10-20 11:01:57 +00:00
from . import models
2016-10-08 16:12:18 +00:00
class ProxyLogSerializer(serializers.ModelSerializer):
2016-10-26 11:10:14 +00:00
time = serializers.SerializerMethodField()
command_length = serializers.SerializerMethodField()
2016-10-08 16:12:18 +00:00
class Meta:
model = models.ProxyLog
2016-10-25 15:23:01 +00:00
fields = ['id', 'name', 'username', 'hostname', 'ip', 'system_user', 'login_type', 'terminal',
2016-11-04 17:15:25 +00:00
'log_file', 'was_failed', 'is_finished', 'date_start', 'date_finished', 'time',
'command_length', "commands_dict"]
2016-10-26 11:10:14 +00:00
@staticmethod
def get_time(obj):
2016-10-27 11:35:02 +00:00
if not obj.is_finished:
return ''
else:
return timesince(obj.date_start, since=obj.date_finished)
2016-10-26 11:10:14 +00:00
@staticmethod
def get_command_length(obj):
2016-11-04 17:15:25 +00:00
return len(obj.commands.all())
2016-10-08 16:12:18 +00:00
class CommandLogSerializer(serializers.ModelSerializer):
class Meta:
model = models.CommandLog