mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 16:33:47 +00:00
Cree des nouvelles vues pour les MX et Ns, proprifie la vue alias
This commit is contained in:
parent
1de35ba16c
commit
b91121ba0a
3 changed files with 54 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
||||||
#Augustin Lemesle
|
#Augustin Lemesle
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from machines.models import Interface, IpType, Extension, IpList, MachineType, Alias
|
from machines.models import Interface, IpType, Extension, IpList, MachineType, Alias, Mx, Ns
|
||||||
|
|
||||||
class IpTypeField(serializers.RelatedField):
|
class IpTypeField(serializers.RelatedField):
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
|
@ -23,24 +23,46 @@ class InterfaceSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class ExtensionNameField(serializers.RelatedField):
|
class ExtensionNameField(serializers.RelatedField):
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
return value.name
|
return value.alias
|
||||||
|
|
||||||
class TypeSerializer(serializers.ModelSerializer):
|
class MxSerializer(serializers.ModelSerializer):
|
||||||
extension = ExtensionNameField(read_only=True)
|
name = serializers.SerializerMethodField('get_alias_name')
|
||||||
|
zone = serializers.SerializerMethodField('get_zone_name')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = IpType
|
model = Mx
|
||||||
fields = ('type', 'extension', 'domaine_ip', 'domaine_range')
|
fields = ('zone', 'priority', 'name')
|
||||||
|
|
||||||
|
def get_alias_name(self, obj):
|
||||||
|
return obj.name.alias + obj.name.extension.name
|
||||||
|
|
||||||
|
def get_zone_name(self, obj):
|
||||||
|
return obj.zone.name
|
||||||
|
|
||||||
|
class NsSerializer(serializers.ModelSerializer):
|
||||||
|
zone = serializers.SerializerMethodField('get_zone_name')
|
||||||
|
interface = serializers.SerializerMethodField('get_interface_name')
|
||||||
|
|
||||||
class InterfaceDNS_ExtensionSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Interface
|
model = Ns
|
||||||
fields = ('ipv4', 'dns')
|
fields = ('zone', 'interface')
|
||||||
|
|
||||||
|
def get_zone_name(self, obj):
|
||||||
|
return obj.zone.name
|
||||||
|
|
||||||
|
def get_interface_name(self, obj):
|
||||||
|
return obj.interface.dns + obj.interface.ipv4.ip_type.extension.name
|
||||||
|
|
||||||
class AliasSerializer(serializers.ModelSerializer):
|
class AliasSerializer(serializers.ModelSerializer):
|
||||||
interface_parent = InterfaceDNS_ExtensionSerializer(read_only=True)
|
interface_parent = serializers.SerializerMethodField('get_interface_name')
|
||||||
extension = ExtensionNameField(read_only=True)
|
extension = serializers.SerializerMethodField('get_zone_name')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Alias
|
model = Alias
|
||||||
fields = ('interface_parent', 'alias', 'extension')
|
fields = ('interface_parent', 'alias', 'extension')
|
||||||
|
|
||||||
|
def get_zone_name(self, obj):
|
||||||
|
return obj.extension.name
|
||||||
|
|
||||||
|
def get_interface_name(self, obj):
|
||||||
|
return obj.interface_parent.dns + obj.interface_parent.ipv4.ip_type.extension.name
|
||||||
|
|
|
@ -44,4 +44,6 @@ urlpatterns = [
|
||||||
url(r'^rest/mac-ip-dns/$', views.mac_ip_dns, name='mac-ip-dns'),
|
url(r'^rest/mac-ip-dns/$', views.mac_ip_dns, name='mac-ip-dns'),
|
||||||
url(r'^rest/alias/$', views.alias, name='alias'),
|
url(r'^rest/alias/$', views.alias, name='alias'),
|
||||||
url(r'^rest/corresp/$', views.corresp, name='corresp'),
|
url(r'^rest/corresp/$', views.corresp, name='corresp'),
|
||||||
]
|
url(r'^rest/mx/$', views.mx, name='mx'),
|
||||||
|
url(r'^rest/ns/$', views.ns, name='ns'),
|
||||||
|
]
|
||||||
|
|
|
@ -16,7 +16,7 @@ from django.contrib.auth import authenticate, login
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
from rest_framework.renderers import JSONRenderer
|
from rest_framework.renderers import JSONRenderer
|
||||||
from machines.serializers import InterfaceSerializer, TypeSerializer, AliasSerializer
|
from machines.serializers import InterfaceSerializer, TypeSerializer, AliasSerializer, MxSerializer, NsSerializer
|
||||||
from reversion import revisions as reversion
|
from reversion import revisions as reversion
|
||||||
|
|
||||||
|
|
||||||
|
@ -667,14 +667,8 @@ def interface_list(request):
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('serveur')
|
@permission_required('serveur')
|
||||||
def alias(request):
|
def alias(request):
|
||||||
alias = Alias.objects.all()
|
alias = Alias.objects.filter(interface_parent=Interface.objects.exclude(ipv4=None))
|
||||||
seria = AliasSerializer(alias, many=True)
|
seria = AliasSerializer(alias, many=True)
|
||||||
for d in seria.data:
|
|
||||||
if d["interface_parent"]["ipv4"]:
|
|
||||||
id = d["interface_parent"]["ipv4"]
|
|
||||||
ip_list = IpList.objects.get(pk=id)
|
|
||||||
d["interface_parent"]["extension"] = ip_list.ip_type.extension.name
|
|
||||||
d["interface_parent"].pop("ipv4")
|
|
||||||
return JSONResponse(seria.data)
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -685,6 +679,22 @@ def corresp(request):
|
||||||
seria = TypeSerializer(type, many=True)
|
seria = TypeSerializer(type, many=True)
|
||||||
return JSONResponse(seria.data)
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@login_required
|
||||||
|
@permission_required('serveur')
|
||||||
|
def mx(request):
|
||||||
|
mx = Mx.objects.all()
|
||||||
|
seria = MxSerializer(mx, many=True)
|
||||||
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@login_required
|
||||||
|
@permission_required('serveur')
|
||||||
|
def ns(request):
|
||||||
|
ns = Ns.objects.filter(interface=Interface.objects.exclude(ipv4=None))
|
||||||
|
seria = NsSerializer(ns, many=True)
|
||||||
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('serveur')
|
@permission_required('serveur')
|
||||||
|
|
Loading…
Reference in a new issue