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

Modif sur la corresp, plus propre

This commit is contained in:
Dalahro 2016-11-16 19:30:48 +01:00
parent 4b6c2d259d
commit 819f6bc20f
2 changed files with 24 additions and 21 deletions

View file

@ -1,16 +1,35 @@
#Augustin Lemesle #Augustin Lemesle
from rest_framework import serializers from rest_framework import serializers
from machines.models import Interface, IpType from machines.models import Interface, IpType, Extension, IpList, MachineType
class IpTypeField(serializers.RelatedField):
def to_representation(self, value):
return value.type
class IpListSerializer(serializers.ModelSerializer):
ip_type = IpTypeField(read_only=True)
class Meta:
model = IpList
fields = ('ipv4', 'ip_type')
class InterfaceSerializer(serializers.ModelSerializer): class InterfaceSerializer(serializers.ModelSerializer):
ipv4 = IpListSerializer(read_only=True)
class Meta: class Meta:
model = Interface model = Interface
fields = ('ipv4', 'mac_address', 'dns', 'type') fields = ('ipv4', 'mac_address', 'dns')
class ExtensionNameField(serializers.RelatedField):
def to_reprsentation(self,value):
return value.name
class TypeSerializer(serializers.ModelSerializer): class TypeSerializer(serializers.ModelSerializer):
extension = ExtensionNameField(read_only=True)
class Meta: class Meta:
model = IpType model = IpType
fields = ('type', 'extension') fields = ('type', 'extension', 'domaine_ip', 'domaine_range')

View file

@ -449,26 +449,10 @@ def history(request, object, id):
class JSONResponse(HttpResponse): class JSONResponse(HttpResponse):
def __init__(self, data, **kwargs): def __init__(self, data, **kwargs):
for d in data:
if d["ipv4"]:
ip = IpList.objects.get(pk=d["ipv4"])
d["ipv4"]= ip.__str__()
d["type"]= ip.ip_type.__str__()
d["extension"] = ip.ip_type.extension.__str__()
content = JSONRenderer().render(data) content = JSONRenderer().render(data)
kwargs['content_type'] = 'application/json' kwargs['content_type'] = 'application/json'
super(JSONResponse, self).__init__(content, **kwargs) super(JSONResponse, self).__init__(content, **kwargs)
class JSONRespType(HttpResponse):
def __init__(self, data, **kwargs):
for d in data:
if d["extension"]:
extension = Extension.objects.get(pk=d["extension"])
d["extension"]=extension.__str__()
content = JSONRenderer().render(data)
kwargs['content_type'] = 'application/json'
super(JSONRespType, self).__init__(content, **kwargs)
@csrf_exempt @csrf_exempt
@login_required @login_required
@permission_required('serveur') @permission_required('serveur')
@ -510,7 +494,7 @@ def mac_ip_dns(request):
@permission_required('serveur') @permission_required('serveur')
def corresp(request): def corresp(request):
seria = type_list(request) seria = type_list(request)
return JSONRespType(seria) return JSONResponse(seria)
@csrf_exempt @csrf_exempt
def login_user(request): def login_user(request):