forked from ungleich-public/ipv6ula
Add support for generating random prefixes
This commit is contained in:
parent
14d88f71cb
commit
23fa1ca386
6 changed files with 45 additions and 7 deletions
|
|
@ -32,7 +32,6 @@ def validate_ula_prefix(prefix):
|
|||
)
|
||||
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -22,11 +22,17 @@
|
|||
<div class="collapse navbar-collapse"
|
||||
id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item"> <a class="nav-link"
|
||||
href="/generate">Generate new prefix</a></li>
|
||||
<li class="nav-item"> <a class="nav-link"
|
||||
href="/submit">Submit existing prefix</a></li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/random/">Generate random prefix</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/generate/">Register random
|
||||
prefix</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/submit/">Submit existing
|
||||
prefix</a>
|
||||
</li>
|
||||
{% if user.is_authenticated %}
|
||||
<span class="navbar-text">Logged in as {{ user }}.</span>
|
||||
<li class="nav-item">
|
||||
|
|
|
|||
15
ipv6ula/templates/ipv6ula/random_ula.html
Normal file
15
ipv6ula/templates/ipv6ula/random_ula.html
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{% extends 'ipv6ula/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Your random ULA prefix</h1>
|
||||
<p>Your randomly generated prefix is:
|
||||
<strong>{{ prefix }}/48</strong>
|
||||
</p>.
|
||||
<p>If you prefer another prefix, just reload this page.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -31,7 +31,8 @@
|
|||
|
||||
<p>
|
||||
To login and submit prefixes you need to create an
|
||||
<a href="https://account.ungleich.ch">ungleich account</a>.
|
||||
<a href="https://account.ungleich.ch">ungleich account</a>. A
|
||||
total of {{ count }} prefixes have been registered.
|
||||
</p>
|
||||
</div>
|
||||
{% if messages %}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ urlpatterns = [
|
|||
path('', views.IndexView.as_view(), name='index'),
|
||||
path('submit/', views.SubmitView.as_view(), name='submit'),
|
||||
path('generate/', views.GenerateView.as_view(), name='generate'),
|
||||
path('random/', views.RandowULAView.as_view(), name='random'),
|
||||
path('login/', views.LoginView.as_view(), name='login'),
|
||||
path('logout/', views.logout_view, name='logout'),
|
||||
path('admin/', admin.site.urls),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from django.views.generic.list import ListView
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
|
|
@ -19,6 +21,20 @@ class IndexView(ListView):
|
|||
model = ULA
|
||||
queryset = ULA.objects.order_by('prefix')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['count'] = self.get_queryset().count()
|
||||
return context
|
||||
|
||||
class RandowULAView(TemplateView):
|
||||
model = ULA
|
||||
template_name = "ipv6ula/random_ula.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['prefix'] = str(random_ula_net())
|
||||
return context
|
||||
|
||||
class GenerateSubmitView(LoginRequiredMixin, SuccessMessageMixin, CreateView):
|
||||
model = ULA
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue