[Django #9] update for overlap funtion
This commit is contained in:
parent
5252d230ff
commit
e7c1b3c12a
3 changed files with 36 additions and 6 deletions
13
kjg/IPv6/ula/ularegistry/checkip.py
Normal file
13
kjg/IPv6/ula/ularegistry/checkip.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
import ipaddress
|
||||
|
||||
def overlapip(ip1, ip2):
|
||||
|
||||
test1 = ipaddress.IPv6Network(ip1).overlaps(ipaddress.IPv6Network(ip2))
|
||||
|
||||
if test1 :
|
||||
print("overlap")
|
||||
return 0
|
||||
else:
|
||||
print("no overlap")
|
||||
return 1
|
||||
|
|
@ -6,9 +6,9 @@
|
|||
{% if ips_list %}
|
||||
<ul>
|
||||
{% for ips in ips_list %}
|
||||
<li><a href="/ularegistry/{{ ips.id }}/">{{ ips.inet }}</a></li>
|
||||
<li>{{ ips.inet }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No polls are available.</p>
|
||||
<p>No registered IP.</p>
|
||||
{% endif %}
|
||||
|
|
|
@ -1,24 +1,41 @@
|
|||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from .forms import ip
|
||||
#from .forms import PostForm
|
||||
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():
|
||||
q = ips(inet=form.cleaned_data['inputIP'])
|
||||
q.save()
|
||||
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()
|
||||
|
||||
ips_list = ips.objects.all()
|
||||
ctx = { 'form' : form,
|
||||
'ips_list' : ips_list,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue