Commit 8e5464a1 authored by Dalahro's avatar Dalahro

Pour le dns

parent 80fcc69e
......@@ -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')
......@@ -16,6 +16,7 @@ urlpatterns = [
url(r'^edit_extension/(?P<extensionid>[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'),
]
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment