mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 19:33:11 +00:00
Pour le dns
This commit is contained in:
parent
d275ba84b2
commit
5816cb1603
3 changed files with 22 additions and 10 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue