mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Modif sur la corresp, plus propre
This commit is contained in:
parent
e538d3b2dc
commit
226d125a97
2 changed files with 24 additions and 21 deletions
|
@ -1,16 +1,35 @@
|
|||
#Augustin Lemesle
|
||||
|
||||
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):
|
||||
ipv4 = IpListSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
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):
|
||||
extension = ExtensionNameField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = IpType
|
||||
fields = ('type', 'extension')
|
||||
fields = ('type', 'extension', 'domaine_ip', 'domaine_range')
|
||||
|
||||
|
||||
|
|
|
@ -449,26 +449,10 @@ def history(request, object, id):
|
|||
|
||||
class JSONResponse(HttpResponse):
|
||||
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)
|
||||
kwargs['content_type'] = 'application/json'
|
||||
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
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
|
@ -510,7 +494,7 @@ def mac_ip_dns(request):
|
|||
@permission_required('serveur')
|
||||
def corresp(request):
|
||||
seria = type_list(request)
|
||||
return JSONRespType(seria)
|
||||
return JSONResponse(seria)
|
||||
|
||||
@csrf_exempt
|
||||
def login_user(request):
|
||||
|
|
Loading…
Reference in a new issue