[Django #11] Limiting to ULA

This commit is contained in:
kjg 2020-08-07 22:10:45 +09:00
parent 572fe59719
commit c29ae7a47b
4 changed files with 62 additions and 1 deletions

View file

@ -10,3 +10,7 @@ class ip_random(forms.Form):
NetworkName = forms.CharField()
NetworkDescription = forms.CharField()
class new_ip_random(forms.Form):
NetworkName = forms.CharField()
NetworkDescription = forms.CharField()

View file

@ -0,0 +1,16 @@
<form action="" method="post">
{% csrf_token %}
<table>
{{ form2 }}
</table>
<input type="submit" value="random create">
</form>
{% if ips_listr %}
<ul>
{% for ips2 in ips_listr %}
<li>{{ ips2.inet2 }} {{ ips2.inet2_name}} {{ ips2.inet2_descrip }} </li>
{% endfor %}
</ul>
{% else %}
<p>No registered IP.</p>
{% endif %}

View file

@ -5,4 +5,5 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
path('randomIP', views.randomIP, name='randomIP'),
path('newrandomIP', views.newrandomIP, name='newrandomIP'),
]

View file

@ -1,6 +1,6 @@
from django.shortcuts import render
from django.http import HttpResponse
from .forms import ip, ip_random
from .forms import ip_random, new_ip_random, ip
from ularegistry.models import ips, ips2
from django.shortcuts import redirect
from ularegistry.checkip import *
@ -84,3 +84,43 @@ def randomIP(request):
return render(request, 'randomIP.html', ctx)
def newrandomIP(request):
ips_listr = ips2.objects.values()
if request.method == "POST":
form2 = new_ip_random(request.POST)
print(form2)
if form2.is_valid():
while True:
newIP = createIP("fd00::/8")
print("test3")
ips_listr2 = list(ips_listr)
if not ips_listr2:
print("test2")
q = ips2(inet2=newIP, inet2_name=form2.cleaned_data['NetworkName'], inet2_descrip=form2.cleaned_data['NetworkDescription'])
q.save()
break
overlapchk = 0
for value in ips_listr2:
if overlapip(newIP,value['inet2']):
overlapchk = 1
print(overlapchk)
q = ips2(inet2=newIP, inet2_name=form2.cleaned_data['NetworkName'], inet2_descrip=form2.cleaned_data['NetworkDescription'])
q.save()
break
else:
overlapchk = 0
if overlapchk:
break
return redirect('newrandomIP')
else:
form2 = new_ip_random()
ctx2 = { 'form2' : form2,
'ips_listr' : ips_listr,
}
return render(request, 'newrandomIP.html', ctx2)