mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 11:53:12 +00:00
Encore une vue pour Chirac, vue d'alis
This commit is contained in:
parent
51c725f36f
commit
aac17cbd92
3 changed files with 32 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
|||
#Augustin Lemesle
|
||||
|
||||
from rest_framework import serializers
|
||||
from machines.models import Interface, IpType, Extension, IpList, MachineType
|
||||
from machines.models import Interface, IpType, Extension, IpList, MachineType, Alias
|
||||
|
||||
class IpTypeField(serializers.RelatedField):
|
||||
def to_representation(self, value):
|
||||
|
@ -22,7 +22,7 @@ class InterfaceSerializer(serializers.ModelSerializer):
|
|||
fields = ('ipv4', 'mac_address', 'dns')
|
||||
|
||||
class ExtensionNameField(serializers.RelatedField):
|
||||
def to_reprsentation(self,value):
|
||||
def to_reprsentation(self, value):
|
||||
return value.name
|
||||
|
||||
class TypeSerializer(serializers.ModelSerializer):
|
||||
|
@ -32,4 +32,21 @@ class TypeSerializer(serializers.ModelSerializer):
|
|||
model = IpType
|
||||
fields = ('type', 'extension', 'domaine_ip', 'domaine_range')
|
||||
|
||||
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)
|
||||
|
||||
class Meta:
|
||||
model = Alias
|
||||
fields = ('interface_parent', 'alias', 'extension')
|
||||
|
|
|
@ -29,5 +29,6 @@ urlpatterns = [
|
|||
url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'),
|
||||
url(r'^rest/login/$', views.login_user, name='login'),
|
||||
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/corresp/$', views.corresp, name='corresp'),
|
||||
]
|
||||
|
|
|
@ -16,12 +16,12 @@ 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
|
||||
from machines.serializers import InterfaceSerializer, TypeSerializer, AliasSerializer
|
||||
from reversion import revisions as reversion
|
||||
|
||||
|
||||
import re
|
||||
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm
|
||||
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm, Alias
|
||||
from .forms import IpTypeForm, DelIpTypeForm, NewAliasForm, EditAliasFullForm
|
||||
from .models import IpType, Machine, Interface, IpList, MachineType, Extension
|
||||
from users.models import User
|
||||
|
@ -468,10 +468,18 @@ def interface_list(request):
|
|||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
def type_list(request):
|
||||
def alias(request):
|
||||
alias = Alias.objects.all()
|
||||
seria = AliasSerializer(alias, many=True)
|
||||
return JSONResponse(seria.data)
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
def corresp(request):
|
||||
type = IpType.objects.all()
|
||||
seria = TypeSerializer(type, many=True)
|
||||
return seria.data
|
||||
return JSONResponse(seria.data)
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
|
@ -489,13 +497,6 @@ def mac_ip_dns(request):
|
|||
seria = interface_list(request)
|
||||
return JSONResponse(seria)
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
def corresp(request):
|
||||
seria = type_list(request)
|
||||
return JSONResponse(seria)
|
||||
|
||||
@csrf_exempt
|
||||
def login_user(request):
|
||||
user = authenticate(username=request.POST['username'], password=request.POST['password'])
|
||||
|
|
Loading…
Reference in a new issue