From 5816cb1603187966b7ae8bd313209439e68d7cff Mon Sep 17 00:00:00 2001 From: Dalahro Date: Tue, 19 Jul 2016 21:43:24 +0200 Subject: [PATCH] Pour le dns --- machines/serializers.py | 3 ++- machines/urls.py | 3 ++- machines/views.py | 26 ++++++++++++++++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/machines/serializers.py b/machines/serializers.py index 2aa7db08..375c4113 100644 --- a/machines/serializers.py +++ b/machines/serializers.py @@ -4,6 +4,7 @@ from machines.models import Interface class InterfaceSerializer( serializers.ModelSerializer): class Meta: model = Interface - fields = ('id','ipv4', 'mac_address') + fields = ('ipv4', 'mac_address', 'dns') + diff --git a/machines/urls.py b/machines/urls.py index efa3af9d..3205ddb9 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -16,6 +16,7 @@ urlpatterns = [ url(r'^edit_extension/(?P[0-9]+)$', views.edit_extension, name='edit-extension'), url(r'^del_extension/$', views.del_extension, name='del-extension'), url(r'^index_extension/$', views.index_extension, name='index-extension'), - url(r'^rest/mac-ip/$', views.interface_list, name='interface-list'), url(r'^$', views.index, name='index'), + url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'), + url(r'^rest/dns-ip/$', views.dns_ip, name='dns-ip'), ] diff --git a/machines/views.py b/machines/views.py index 35481480..1774a6a2 100644 --- a/machines/views.py +++ b/machines/views.py @@ -290,21 +290,31 @@ def index_extension(request): class JSONResponse(HttpResponse): def __init__(self, data, **kwargs): - datas=[] for d in data: - interface = Interface.objects.get(pk=d["id"]) - d.pop("id") - if d["ipv4"] and interface.is_active(): + if d["ipv4"]: d["ipv4"]= IpList.objects.get(pk=d["ipv4"]).__str__() - datas.append(d) - content = JSONRenderer().render(datas) + content = JSONRenderer().render(data) kwargs['content_type'] = 'application/json' super(JSONResponse, self).__init__(content, **kwargs) def interface_list(request): interfaces = Interface.objects.all() - seria = InterfaceSerializer(interfaces, many=True) - return JSONResponse(seria.data) + interface = [] + for i in interfaces : + if i.ipv4 and i.is_active(): + interface.append(i) + seria = InterfaceSerializer(interface, many=True) + return seria.data +def mac_ip(request): + seria = interface_list(request) + for s in seria: + s.pop('dns') + return JSONResponse(seria) +def dns_ip(request): + seria = interface_list(request) + for s in seria: + s.pop('mac_address') + return JSONResponse(seria)