From fa0c4c10511e3c90b8f77085a7bef00a980791d3 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 4 Dec 2020 21:30:59 +0100 Subject: [PATCH] Lots of cleanups --- ipv6ula/admin.py | 2 +- ipv6ula/migrations/0001_initial.py | 19 ++++++- ipv6ula/migrations/0002_auto_20201204_2019.py | 18 ++++++ ipv6ula/migrations/0002_bookmarkmodel.py | 23 -------- .../0003_bookmarkmodel_posted_at.py | 20 ------- ipv6ula/models.py | 23 ++++++-- ipv6ula/settings.py | 52 ++++++++--------- .../{ubookmark => ipv6ula}/base.html | 4 +- .../bookmarkmodel_form.html | 0 .../{ubookmark => ipv6ula}/login.html | 0 ipv6ula/templates/ipv6ula/ula_list.html | 27 +++++++++ .../ubookmark/bookmarkmodel_list.html | 29 ---------- ipv6ula/urls.py | 6 +- ipv6ula/views.py | 56 ++++++++----------- 14 files changed, 136 insertions(+), 143 deletions(-) create mode 100644 ipv6ula/migrations/0002_auto_20201204_2019.py delete mode 100644 ipv6ula/migrations/0002_bookmarkmodel.py delete mode 100644 ipv6ula/migrations/0003_bookmarkmodel_posted_at.py rename ipv6ula/templates/{ubookmark => ipv6ula}/base.html (96%) rename ipv6ula/templates/{ubookmark => ipv6ula}/bookmarkmodel_form.html (100%) rename ipv6ula/templates/{ubookmark => ipv6ula}/login.html (100%) create mode 100644 ipv6ula/templates/ipv6ula/ula_list.html delete mode 100644 ipv6ula/templates/ubookmark/bookmarkmodel_list.html diff --git a/ipv6ula/admin.py b/ipv6ula/admin.py index 8198666..8e12cdf 100644 --- a/ipv6ula/admin.py +++ b/ipv6ula/admin.py @@ -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) diff --git a/ipv6ula/migrations/0001_initial.py b/ipv6ula/migrations/0001_initial.py index 69c4c24..95a7d65 100644 --- a/ipv6ula/migrations/0001_initial.py +++ b/ipv6ula/migrations/0001_initial.py @@ -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)), + ], + ), ] diff --git a/ipv6ula/migrations/0002_auto_20201204_2019.py b/ipv6ula/migrations/0002_auto_20201204_2019.py new file mode 100644 index 0000000..61e6172 --- /dev/null +++ b/ipv6ula/migrations/0002_auto_20201204_2019.py @@ -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), + ), + ] diff --git a/ipv6ula/migrations/0002_bookmarkmodel.py b/ipv6ula/migrations/0002_bookmarkmodel.py deleted file mode 100644 index 1902cd4..0000000 --- a/ipv6ula/migrations/0002_bookmarkmodel.py +++ /dev/null @@ -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)), - ], - ), - ] diff --git a/ipv6ula/migrations/0003_bookmarkmodel_posted_at.py b/ipv6ula/migrations/0003_bookmarkmodel_posted_at.py deleted file mode 100644 index daa6c4b..0000000 --- a/ipv6ula/migrations/0003_bookmarkmodel_posted_at.py +++ /dev/null @@ -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, - ), - ] diff --git a/ipv6ula/models.py b/ipv6ula/models.py index 31cb8a8..33055ca 100644 --- a/ipv6ula/models.py +++ b/ipv6ula/models.py @@ -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}" diff --git a/ipv6ula/settings.py b/ipv6ula/settings.py index 8a418e3..f2ee0dc 100644 --- a/ipv6ula/settings.py +++ b/ipv6ula/settings.py @@ -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 diff --git a/ipv6ula/templates/ubookmark/base.html b/ipv6ula/templates/ipv6ula/base.html similarity index 96% rename from ipv6ula/templates/ubookmark/base.html rename to ipv6ula/templates/ipv6ula/base.html index 9762a98..d2d58c0 100644 --- a/ipv6ula/templates/ubookmark/base.html +++ b/ipv6ula/templates/ipv6ula/base.html @@ -10,7 +10,7 @@ - {{ site_name }} powered by ipv6ula + The IPv6 ULA registry