2016-11-12 15:12:24 +00:00
|
|
|
#Augustin Lemesle
|
|
|
|
|
2016-07-18 21:22:59 +00:00
|
|
|
from rest_framework import serializers
|
2016-11-18 17:15:57 +00:00
|
|
|
from machines.models import Interface, IpType, Extension, IpList, MachineType, Alias
|
2016-07-18 21:22:59 +00:00
|
|
|
|
2016-11-16 18:30:48 +00:00
|
|
|
class IpTypeField(serializers.RelatedField):
|
|
|
|
def to_representation(self, value):
|
|
|
|
return value.type
|
|
|
|
|
|
|
|
class IpListSerializer(serializers.ModelSerializer):
|
|
|
|
ip_type = IpTypeField(read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = IpList
|
|
|
|
fields = ('ipv4', 'ip_type')
|
|
|
|
|
|
|
|
class InterfaceSerializer(serializers.ModelSerializer):
|
|
|
|
ipv4 = IpListSerializer(read_only=True)
|
|
|
|
|
2016-07-18 21:22:59 +00:00
|
|
|
class Meta:
|
|
|
|
model = Interface
|
2016-11-16 18:30:48 +00:00
|
|
|
fields = ('ipv4', 'mac_address', 'dns')
|
|
|
|
|
|
|
|
class ExtensionNameField(serializers.RelatedField):
|
2016-11-18 17:15:57 +00:00
|
|
|
def to_reprsentation(self, value):
|
2016-11-16 18:30:48 +00:00
|
|
|
return value.name
|
2016-07-19 19:43:24 +00:00
|
|
|
|
2016-11-12 15:12:24 +00:00
|
|
|
class TypeSerializer(serializers.ModelSerializer):
|
2016-11-16 18:30:48 +00:00
|
|
|
extension = ExtensionNameField(read_only=True)
|
|
|
|
|
2016-11-12 15:12:24 +00:00
|
|
|
class Meta:
|
|
|
|
model = IpType
|
2016-11-16 18:30:48 +00:00
|
|
|
fields = ('type', 'extension', 'domaine_ip', 'domaine_range')
|
2016-07-18 21:22:59 +00:00
|
|
|
|
2016-11-18 17:15:57 +00:00
|
|
|
class IpList_ExtensionField(serializers.RelatedField):
|
|
|
|
def to_representation(self, value):
|
|
|
|
return value.ipv4.ip_type.extension.name
|
|
|
|
|
|
|
|
class InterfaceDNS_ExtensionSerializer(serializers.ModelSerializer):
|
|
|
|
ipv4 = IpList_ExtensionField(read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Interface
|
|
|
|
fields = ('ipv4', 'dns')
|
|
|
|
|
|
|
|
class AliasSerializer(serializers.ModelSerializer):
|
|
|
|
interface_parent = InterfaceDNS_ExtensionSerializer(read_only=True)
|
|
|
|
extension = ExtensionNameField(read_only=True)
|
2016-07-18 21:22:59 +00:00
|
|
|
|
2016-11-18 17:15:57 +00:00
|
|
|
class Meta:
|
|
|
|
model = Alias
|
|
|
|
fields = ('interface_parent', 'alias', 'extension')
|