mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:03:10 +00:00
parce que chirac est compliqué
This commit is contained in:
parent
1cdbc6ae9b
commit
d82e1af4fd
3 changed files with 35 additions and 2 deletions
|
@ -1,10 +1,16 @@
|
|||
#Augustin Lemesle
|
||||
|
||||
from rest_framework import serializers
|
||||
from machines.models import Interface
|
||||
from machines.models import Interface, IpType
|
||||
|
||||
class InterfaceSerializer( serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Interface
|
||||
fields = ('ipv4', 'mac_address', 'dns', 'type')
|
||||
|
||||
class TypeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = IpType
|
||||
fields = ('type', 'extension')
|
||||
|
||||
|
||||
|
|
|
@ -29,4 +29,5 @@ urlpatterns = [
|
|||
url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'),
|
||||
url(r'^rest/login/$', views.login_user, name='login'),
|
||||
url(r'^rest/mac-ip-dns/$', views.mac_ip_dns, name='mac-ip-dns'),
|
||||
url(r'^rest/corresp/$', views.corresp, name='corresp'),
|
||||
]
|
||||
|
|
|
@ -16,7 +16,7 @@ from django.contrib.auth import authenticate, login
|
|||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from machines.serializers import InterfaceSerializer
|
||||
from machines.serializers import InterfaceSerializer, TypeSerializer
|
||||
from reversion import revisions as reversion
|
||||
|
||||
|
||||
|
@ -454,10 +454,21 @@ class JSONResponse(HttpResponse):
|
|||
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')
|
||||
|
@ -470,6 +481,14 @@ def interface_list(request):
|
|||
seria = InterfaceSerializer(interface, many=True)
|
||||
return seria.data
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
def type_list(request):
|
||||
type = IpType.objects.all()
|
||||
seria = TypeSerializer(type, many=True)
|
||||
return seria.data
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
|
@ -486,6 +505,13 @@ def mac_ip_dns(request):
|
|||
seria = interface_list(request)
|
||||
return JSONResponse(seria)
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('serveur')
|
||||
def corresp(request):
|
||||
seria = type_list(request)
|
||||
return JSONRespType(seria)
|
||||
|
||||
@csrf_exempt
|
||||
def login_user(request):
|
||||
user = authenticate(username=request.POST['username'], password=request.POST['password'])
|
||||
|
|
Loading…
Reference in a new issue