[Django #11] Limiting to ULA
This commit is contained in:
parent
572fe59719
commit
c29ae7a47b
4 changed files with 62 additions and 1 deletions
|
@ -10,3 +10,7 @@ class ip_random(forms.Form):
|
||||||
NetworkName = forms.CharField()
|
NetworkName = forms.CharField()
|
||||||
NetworkDescription = forms.CharField()
|
NetworkDescription = forms.CharField()
|
||||||
|
|
||||||
|
class new_ip_random(forms.Form):
|
||||||
|
NetworkName = forms.CharField()
|
||||||
|
NetworkDescription = forms.CharField()
|
||||||
|
|
||||||
|
|
16
kjg/IPv6/ula/ularegistry/templates/newrandomIP.html
Normal file
16
kjg/IPv6/ula/ularegistry/templates/newrandomIP.html
Normal 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 %}
|
|
@ -5,4 +5,5 @@ from . import views
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('randomIP', views.randomIP, name='randomIP'),
|
path('randomIP', views.randomIP, name='randomIP'),
|
||||||
|
path('newrandomIP', views.newrandomIP, name='newrandomIP'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
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 ularegistry.models import ips, ips2
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from ularegistry.checkip import *
|
from ularegistry.checkip import *
|
||||||
|
@ -84,3 +84,43 @@ def randomIP(request):
|
||||||
return render(request, 'randomIP.html', ctx)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue