From 18ae1b668200df759d7c71420a74a98f6503a4db Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 20 Nov 2016 05:12:36 +0100 Subject: [PATCH] Vue pour les zones, contenant les enregistrement origin --- machines/serializers.py | 10 ++++++++++ machines/urls.py | 1 + machines/views.py | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/machines/serializers.py b/machines/serializers.py index 28f8e012..64d51d94 100644 --- a/machines/serializers.py +++ b/machines/serializers.py @@ -32,6 +32,16 @@ class TypeSerializer(serializers.ModelSerializer): model = IpType fields = ('type', 'extension', 'domaine_ip', 'domaine_range') +class ExtensionSerializer(serializers.ModelSerializer): + origin = serializers.SerializerMethodField('get_origin_ip') + + class Meta: + model = Extension + fields = ('name', 'origin') + + def get_origin_ip(self, obj): + return obj.origin.ipv4 + class MxSerializer(serializers.ModelSerializer): name = serializers.SerializerMethodField('get_alias_name') zone = serializers.SerializerMethodField('get_zone_name') diff --git a/machines/urls.py b/machines/urls.py index 212c84c0..47710d71 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -46,4 +46,5 @@ urlpatterns = [ url(r'^rest/corresp/$', views.corresp, name='corresp'), url(r'^rest/mx/$', views.mx, name='mx'), url(r'^rest/ns/$', views.ns, name='ns'), + url(r'^rest/zones/$', views.zones, name='zones'), ] diff --git a/machines/views.py b/machines/views.py index 9bf4255d..bf1e7ea5 100644 --- a/machines/views.py +++ b/machines/views.py @@ -16,7 +16,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, AliasSerializer, MxSerializer, NsSerializer +from machines.serializers import InterfaceSerializer, TypeSerializer, AliasSerializer, MxSerializer, ExtensionSerializer, NsSerializer from reversion import revisions as reversion @@ -695,6 +695,14 @@ def ns(request): seria = NsSerializer(ns, many=True) return JSONResponse(seria.data) +@csrf_exempt +@login_required +@permission_required('serveur') +def zones(request): + zones = Extension.objects.all() + seria = ExtensionSerializer(zones, many=True) + return JSONResponse(seria.data) + @csrf_exempt @login_required @permission_required('serveur')