2016-10-16 14:12:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
2016-10-18 15:49:04 +00:00
|
|
|
from .models import Terminal, TerminalHeatbeat
|
2016-10-19 10:33:14 +00:00
|
|
|
from .hands import ProxyLog
|
2016-10-16 14:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TerminalSerializer(serializers.ModelSerializer):
|
2016-10-19 10:33:14 +00:00
|
|
|
proxy_amount = serializers.SerializerMethodField()
|
|
|
|
|
2016-10-16 14:12:13 +00:00
|
|
|
class Meta:
|
|
|
|
model = Terminal
|
2016-10-19 10:33:14 +00:00
|
|
|
fields = ['id', 'name', 'ip', 'type', 'url', 'comment', 'is_active',
|
|
|
|
'get_type_display', 'proxy_amount']
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_proxy_amount(obj):
|
|
|
|
return ProxyLog.objects.filter(terminal=obj.name, is_finished=False).count()
|
2016-10-16 14:12:13 +00:00
|
|
|
|
|
|
|
|
2016-10-18 15:49:04 +00:00
|
|
|
class TerminalHeatbeatSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = TerminalHeatbeat
|
|
|
|
fields = ['terminal']
|
|
|
|
|
|
|
|
|
2016-10-16 14:12:13 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
pass
|