Lots of cleanups
This commit is contained in:
parent
f2c1baff02
commit
fa0c4c1051
14 changed files with 136 additions and 143 deletions
|
@ -4,4 +4,4 @@ from django.contrib.auth.admin import UserAdmin
|
|||
from .models import *
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
admin.site.register(BookmarkModel)
|
||||
admin.site.register(ULA)
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# Generated by Django 3.0.5 on 2020-04-25 15:07
|
||||
# Generated by Django 3.1.4 on 2020-12-04 20:03
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
|
@ -11,7 +13,7 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0011_update_proxy_permissions'),
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
@ -23,7 +25,7 @@ class Migration(migrations.Migration):
|
|||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
|
||||
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
|
||||
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
|
||||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
|
||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
|
@ -41,4 +43,15 @@ class Migration(migrations.Migration):
|
|||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ULA',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('prefix', models.GenericIPAddressField(protocol='IPv6')),
|
||||
('name', models.CharField(max_length=256)),
|
||||
('organization', models.CharField(max_length=256)),
|
||||
('website', models.URLField()),
|
||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
18
ipv6ula/migrations/0002_auto_20201204_2019.py
Normal file
18
ipv6ula/migrations/0002_auto_20201204_2019.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.1.4 on 2020-12-04 20:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ipv6ula', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='ula',
|
||||
name='prefix',
|
||||
field=models.GenericIPAddressField(protocol='IPv6', unique=True),
|
||||
),
|
||||
]
|
|
@ -1,23 +0,0 @@
|
|||
# Generated by Django 3.0.5 on 2020-04-25 15:22
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ipv6ula', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='BookmarkModel',
|
||||
fields=[
|
||||
('url', models.URLField(primary_key=True, serialize=False)),
|
||||
('comment', models.CharField(max_length=2048)),
|
||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# Generated by Django 3.0.5 on 2020-04-25 15:57
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ipv6ula', '0002_bookmarkmodel'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='bookmarkmodel',
|
||||
name='posted_at',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -2,20 +2,33 @@ from django.contrib.auth.models import AbstractUser
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
|
||||
import ipaddress
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
pass
|
||||
|
||||
class BookmarkModel(models.Model):
|
||||
class ULA(models.Model):
|
||||
owner = models.ForeignKey(
|
||||
get_user_model(),
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
url = models.URLField(primary_key=True)
|
||||
comment = models.CharField(max_length=2048)
|
||||
posted_at = models.DateTimeField(auto_now_add=True)
|
||||
prefix = models.GenericIPAddressField(protocol='IPv6', unique=True)
|
||||
name = models.CharField(max_length=256)
|
||||
organization = models.CharField(max_length=256)
|
||||
website = models.URLField()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
Ensure we only save the first IPv6 address of the network
|
||||
"""
|
||||
|
||||
net_str = f"{self.prefix}/48"
|
||||
net = ipaddress.IPv6Network(net_str, strict=False)
|
||||
self.prefix = str(net[0])
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return "{} posted by {}".format(self.url, self.owner)
|
||||
return f"{self.prefix}"
|
||||
|
|
|
@ -72,39 +72,34 @@ TEMPLATES = [
|
|||
WSGI_APPLICATION = 'ipv6ula.wsgi.application'
|
||||
|
||||
|
||||
# Defaults vs your settings
|
||||
try:
|
||||
from ipv6ula.local_settings import *
|
||||
LOGGING = {}
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||
|
||||
except (ModuleNotFoundError, ImportError):
|
||||
LOGGING = {}
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||
DEBUG = True
|
||||
|
||||
DEBUG = True
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# LDAP: you probably want to set those, if you are using ipv6ula
|
||||
################################################################################
|
||||
# LDAP: you probably want to set those, if you are using ipv6ula
|
||||
|
||||
AUTH_LDAP_SERVER_URI = ""
|
||||
AUTH_LDAP_SERVER_URI = ""
|
||||
|
||||
AUTH_LDAP_USER_ATTR_MAP = {
|
||||
"first_name": "givenName",
|
||||
"last_name": "sn",
|
||||
"email": "mail"
|
||||
}
|
||||
AUTH_LDAP_USER_ATTR_MAP = {
|
||||
"first_name": "givenName",
|
||||
"last_name": "sn",
|
||||
"email": "mail"
|
||||
}
|
||||
|
||||
AUTH_LDAP_BIND_PASSWORD = ""
|
||||
AUTH_LDAP_USER_SEARCH = ""
|
||||
AUTH_LDAP_BIND_PASSWORD = ""
|
||||
AUTH_LDAP_USER_SEARCH = ""
|
||||
|
||||
SITE_NAME = "an unconfigured site"
|
||||
SITE_DESCRIPTION = "no description"
|
||||
SITE_NAME = "an unconfigured site"
|
||||
SITE_DESCRIPTION = "no description"
|
||||
|
||||
|
||||
# Password validation
|
||||
|
@ -157,3 +152,10 @@ AUTH_USER_MODEL = 'ipv6ula.User'
|
|||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||
|
||||
LOGOUT_URL="/logout"
|
||||
|
||||
# Overwrite in local settings
|
||||
try:
|
||||
from ipv6ula.local_settings import *
|
||||
|
||||
except (ModuleNotFoundError, ImportError):
|
||||
pass
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link rel="stylesheet" href="{% static '/bootstrap/css/bootstrap.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static '/css/sticky-footer-navbar.css' %}">
|
||||
|
||||
<title>{{ site_name }} powered by ipv6ula</title>
|
||||
<title>The IPv6 ULA registry</title>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
|
@ -78,7 +78,7 @@
|
|||
<div class="container">
|
||||
<span class="text-muted">Powered by
|
||||
<a href="http://ungleich.ch/u/projects/ipv6ula">ipv6ula</a>,
|
||||
a FOSS product created by <a href="https://ungleich.ch">ungleich</a>.</span>
|
||||
a FOSS project created by <a href="https://ungleich.ch">ungleich</a>.</span>
|
||||
</div>
|
||||
</footer>
|
||||
|
27
ipv6ula/templates/ipv6ula/ula_list.html
Normal file
27
ipv6ula/templates/ipv6ula/ula_list.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
{% extends 'ipv6ula/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Prefix</th>
|
||||
<th>Name</th>
|
||||
<th>Organization</th>
|
||||
<th>URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for ula in object_list %}
|
||||
<tr>
|
||||
<td>{{ ula.prefix }}</td>
|
||||
<td>{{ ula.name }}</td>
|
||||
<td>{{ ula.organization }}</td>
|
||||
<td><a href="{{ ula.website }}">{{ ula.website }}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,29 +0,0 @@
|
|||
{% extends 'ipv6ula/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{% autoescape off %}
|
||||
{{ site_description }}
|
||||
{% endautoescape %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<ul class="list-group">
|
||||
{% for bookmark in object_list %}
|
||||
<li class="list-group-item">
|
||||
<a href="{{ bookmark.url }}">{{ bookmark.comment }}
|
||||
({{ bookmark.url }}) </a>
|
||||
<div class="text-muted">
|
||||
(posted by {{ bookmark.owner }} on {{ bookmark.posted_at }})
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -20,8 +20,8 @@ from ipv6ula import views
|
|||
|
||||
urlpatterns = [
|
||||
path('', views.IndexView.as_view(), name='index'),
|
||||
path('submit/', views.SubmitView.as_view(), name='submit'),
|
||||
path('login/', views.LoginView.as_view(), name='login'),
|
||||
path('logout/', views.logout_view, name='logout'),
|
||||
# path('submit/', views.SubmitView.as_view(), name='submit'),
|
||||
# path('login/', views.LoginView.as_view(), name='login'),
|
||||
# path('logout/', views.logout_view, name='logout'),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
|
|
@ -11,43 +11,35 @@ from django.conf import settings
|
|||
from ipv6ula.models import *
|
||||
|
||||
class IndexView(ListView):
|
||||
model = BookmarkModel
|
||||
paginate_by = 5
|
||||
queryset = BookmarkModel.objects.order_by('-posted_at')
|
||||
model = ULA
|
||||
paginate_by = 50
|
||||
queryset = ULA.objects.order_by('prefix')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
context['site_name'] = settings.SITE_NAME
|
||||
context['site_description'] = settings.SITE_DESCRIPTION
|
||||
context['site_description'] = settings.SITE_DESCRIPTION
|
||||
# class SubmitView(LoginRequiredMixin, CreateView):
|
||||
# model = BookmarkModel
|
||||
# fields = [ 'comment', 'url' ]
|
||||
# login_url = '/login/'
|
||||
# success_url = '/'
|
||||
|
||||
return context
|
||||
# def get_context_data(self, **kwargs):
|
||||
# context = super(CreateView, self).get_context_data(**kwargs)
|
||||
# context['site_name'] = settings.SITE_NAME
|
||||
# context['site_description'] = settings.SITE_DESCRIPTION
|
||||
|
||||
class SubmitView(LoginRequiredMixin, CreateView):
|
||||
model = BookmarkModel
|
||||
fields = [ 'comment', 'url' ]
|
||||
login_url = '/login/'
|
||||
success_url = '/'
|
||||
# return context
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CreateView, self).get_context_data(**kwargs)
|
||||
context['site_name'] = settings.SITE_NAME
|
||||
context['site_description'] = settings.SITE_DESCRIPTION
|
||||
# def form_valid(self, form):
|
||||
# form.instance.owner = self.request.user
|
||||
# return super(SubmitView, self).form_valid(form)
|
||||
|
||||
return context
|
||||
# class LoginView(auth_views.LoginView):
|
||||
# template_name = 'ipv6ula/login.html'
|
||||
# extra_context = {}
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user
|
||||
return super(SubmitView, self).form_valid(form)
|
||||
|
||||
class LoginView(auth_views.LoginView):
|
||||
template_name = 'ipv6ula/login.html'
|
||||
extra_context = {}
|
||||
|
||||
extra_context['site_name'] = settings.SITE_NAME
|
||||
extra_context['site_description'] = settings.SITE_DESCRIPTION
|
||||
# extra_context['site_name'] = settings.SITE_NAME
|
||||
# extra_context['site_description'] = settings.SITE_DESCRIPTION
|
||||
|
||||
|
||||
def logout_view(request):
|
||||
logout(request)
|
||||
return redirect("/")
|
||||
# def logout_view(request):
|
||||
# logout(request)
|
||||
# return redirect("/")
|
||||
|
|
Loading…
Reference in a new issue