2016-10-16 14:12:13 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2018-03-07 03:28:42 +00:00
|
|
|
from common.mixins import BulkSerializerMixin
|
2019-04-25 02:11:50 +00:00
|
|
|
from common.serializers import AdaptedBulkListSerializer
|
2019-12-05 07:09:25 +00:00
|
|
|
from ..models import (
|
|
|
|
Terminal, Status, Session, Task
|
|
|
|
)
|
2016-10-16 14:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TerminalSerializer(serializers.ModelSerializer):
|
2017-12-01 09:55:19 +00:00
|
|
|
session_online = serializers.SerializerMethodField()
|
2019-01-21 09:43:08 +00:00
|
|
|
is_alive = serializers.BooleanField(read_only=True)
|
2016-10-19 10:33:14 +00:00
|
|
|
|
2016-10-16 14:12:13 +00:00
|
|
|
class Meta:
|
|
|
|
model = Terminal
|
2017-12-25 04:22:49 +00:00
|
|
|
fields = [
|
|
|
|
'id', 'name', 'remote_addr', 'http_port', 'ssh_port',
|
|
|
|
'comment', 'is_accepted', "is_active", 'session_online',
|
2020-04-21 09:37:29 +00:00
|
|
|
'is_alive', 'date_created', 'command_storage', 'replay_storage'
|
2017-12-25 04:22:49 +00:00
|
|
|
]
|
2016-10-19 10:33:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2017-12-01 09:55:19 +00:00
|
|
|
def get_session_online(obj):
|
2019-01-21 09:05:31 +00:00
|
|
|
return Session.objects.filter(terminal=obj, is_finished=False).count()
|
2016-11-13 14:34:38 +00:00
|
|
|
|
2016-10-16 14:12:13 +00:00
|
|
|
|
2017-12-03 12:42:36 +00:00
|
|
|
class StatusSerializer(serializers.ModelSerializer):
|
2017-11-14 01:44:16 +00:00
|
|
|
class Meta:
|
2019-01-21 09:05:31 +00:00
|
|
|
fields = ['id', 'terminal']
|
2017-12-01 09:28:47 +00:00
|
|
|
model = Status
|
2017-10-31 03:34:20 +00:00
|
|
|
|
|
|
|
|
2018-03-07 03:28:42 +00:00
|
|
|
class TaskSerializer(BulkSerializerMixin, serializers.ModelSerializer):
|
2017-11-14 01:44:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
fields = '__all__'
|
2017-12-01 09:28:47 +00:00
|
|
|
model = Task
|
2019-04-25 02:11:50 +00:00
|
|
|
list_serializer_class = AdaptedBulkListSerializer
|