ungleich-learning-circle/kjg/IPv6/ula/ularegistry/views.py

49 lines
1.3 KiB
Python
Raw Normal View History

from django.shortcuts import render
from django.http import HttpResponse
from .forms import ip
from ularegistry.models import ips
from django.shortcuts import redirect
2020-07-30 14:15:52 +00:00
from ularegistry.checkip import *
# Create your views here.
def index(request):
2020-07-30 14:15:52 +00:00
ips_list = ips.objects.values()
if request.method == "POST":
form = ip(request.POST)
print(form)
if form.is_valid():
2020-07-30 14:15:52 +00:00
ips_list2 = list(ips_list)
if not ips_list2:
print("test")
q = ips(inet=form.cleaned_data['inputIP'])
q.save()
overlapchk = 0
for value in ips_list2:
if overlapip(form.cleaned_data['inputIP'],value['inet']):
overlapchk = 1
else:
overlapchk = 0
break
if overlapchk:
print(overlapchk)
q = ips(inet=form.cleaned_data['inputIP'])
q.save()
return redirect('index')
else:
form = ip()
ctx = { 'form' : form,
'ips_list' : ips_list,
}
return render(request, 'index.html', ctx)
#return HttpResponse("Hello, world.")
def results(request, ips_id):
return HttpResponse(ips_id)