Commit 7171891c authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Export des ipv6 en rest

parent abbceb6a
......@@ -55,6 +55,25 @@ class InterfaceSerializer(serializers.ModelSerializer):
def get_macaddress(self, obj):
return str(obj.mac_address)
class FullInterfaceSerializer(serializers.ModelSerializer):
ipv4 = IpListSerializer(read_only=True)
mac_address = serializers.SerializerMethodField('get_macaddress')
domain = serializers.SerializerMethodField('get_dns')
extension = serializers.SerializerMethodField('get_interface_extension')
class Meta:
model = Interface
fields = ('ipv4', 'ipv6', 'mac_address', 'domain', 'extension')
def get_dns(self, obj):
return obj.domain.name
def get_interface_extension(self, obj):
return obj.domain.extension.name
def get_macaddress(self, obj):
return str(obj.mac_address)
class ExtensionNameField(serializers.RelatedField):
def to_representation(self, value):
return value.name
......
......@@ -41,7 +41,7 @@ from django.contrib.auth import authenticate, login
from django.views.decorators.csrf import csrf_exempt
from rest_framework.renderers import JSONRenderer
from machines.serializers import InterfaceSerializer, TypeSerializer, DomainSerializer, TextSerializer, MxSerializer, ExtensionSerializer, ServiceServersSerializer, NsSerializer
from machines.serializers import FullInterfaceSerializer, InterfaceSerializer, TypeSerializer, DomainSerializer, TextSerializer, MxSerializer, ExtensionSerializer, ServiceServersSerializer, NsSerializer
from reversion import revisions as reversion
from reversion.models import Version
......@@ -1027,6 +1027,14 @@ def mac_ip_list(request):
seria = InterfaceSerializer(interfaces, many=True)
return seria.data
@csrf_exempt
@login_required
@permission_required('serveur')
def full_mac_ip_list(request):
interfaces = all_active_assigned_interfaces()
seria = FullInterfaceSerializer(interfaces, many=True)
return seria.data
@csrf_exempt
@login_required
@permission_required('serveur')
......@@ -1086,7 +1094,7 @@ def mac_ip(request):
@login_required
@permission_required('serveur')
def mac_ip_dns(request):
seria = mac_ip_list(request)
seria = full_mac_ip_list(request)
return JSONResponse(seria)
@csrf_exempt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment