8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-27 01:13:46 +00:00

fix serializers

This commit is contained in:
Gabriel Detraz 2016-12-26 00:01:48 +01:00
parent c27eaff5d3
commit 3b8bfe2ec8
2 changed files with 10 additions and 14 deletions

View file

@ -18,13 +18,14 @@ class InterfaceSerializer(serializers.ModelSerializer):
ipv4 = IpListSerializer(read_only=True) ipv4 = IpListSerializer(read_only=True)
mac_address = serializers.SerializerMethodField('get_macaddress') mac_address = serializers.SerializerMethodField('get_macaddress')
dns = serializers.SerializerMethodField('get_dns') dns = serializers.SerializerMethodField('get_dns')
domain = serializers.SerializerMethodField('get_dns')
class Meta: class Meta:
model = Interface model = Interface
fields = ('ipv4', 'mac_address') fields = ('ipv4', 'mac_address', 'domain')
def get_dns(self, obj): def get_dns(self, obj):
return obj.domain_set.all().first() return obj
def get_macaddress(self, obj): def get_macaddress(self, obj):
return str(obj.mac_address) return str(obj.mac_address)
@ -51,15 +52,15 @@ class ExtensionSerializer(serializers.ModelSerializer):
return obj.origin.ipv4 return obj.origin.ipv4
class MxSerializer(serializers.ModelSerializer): class MxSerializer(serializers.ModelSerializer):
name = serializers.SerializerMethodField('get_alias_name') name = serializers.SerializerMethodField('get_name')
zone = serializers.SerializerMethodField('get_zone_name') zone = serializers.SerializerMethodField('get_zone_name')
class Meta: class Meta:
model = Mx model = Mx
fields = ('zone', 'priority', 'name') fields = ('zone', 'priority', 'name')
def get_alias_name(self, obj): def get_name(self, obj):
return obj.name.alias + obj.name.extension.name return obj.name
def get_zone_name(self, obj): def get_zone_name(self, obj):
return obj.zone.name return obj.zone.name
@ -76,22 +77,19 @@ class NsSerializer(serializers.ModelSerializer):
return obj.zone.name return obj.zone.name
def get_interface_name(self, obj): def get_interface_name(self, obj):
return obj.interface.dns + obj.interface.ipv4.ip_type.extension.name return obj.interface
class DomainSerializer(serializers.ModelSerializer): class DomainSerializer(serializers.ModelSerializer):
interface_parent = serializers.SerializerMethodField('get_interface_name')
extension = serializers.SerializerMethodField('get_zone_name') extension = serializers.SerializerMethodField('get_zone_name')
cname = serializers.SerializerMethodField('get_cname') cname = serializers.SerializerMethodField('get_cname')
class Meta: class Meta:
model = Domain model = Domain
fields = ('interface_parent', 'name', 'extension', 'cname') fields = ('name', 'extension', 'cname')
def get_zone_name(self, obj): def get_zone_name(self, obj):
return obj.extension.name return obj.extension.name
def get_cname(self, obj): def get_cname(self, obj):
return obj.cname.name + obj.cname.extension.name return obj.cname
def get_interface_name(self, obj):
return obj.name + obj.extension.name

View file

@ -747,8 +747,6 @@ def zones(request):
@permission_required('serveur') @permission_required('serveur')
def mac_ip(request): def mac_ip(request):
seria = interface_list(request) seria = interface_list(request)
for s in seria:
s.pop('dns')
return JSONResponse(seria) return JSONResponse(seria)
@csrf_exempt @csrf_exempt