48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from django.shortcuts import render
|
|
from django.http import HttpResponse
|
|
from .forms import ip
|
|
from ularegistry.models import ips
|
|
from django.shortcuts import redirect
|
|
from ularegistry.checkip import *
|
|
|
|
# Create your views here.
|
|
def index(request):
|
|
ips_list = ips.objects.values()
|
|
if request.method == "POST":
|
|
form = ip(request.POST)
|
|
print(form)
|
|
if form.is_valid():
|
|
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)
|
|
|