jumpserver/apps/audits/serializers.py

29 lines
666 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
fields = '__all__'
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):
return 2
2016-10-08 16:12:18 +00:00