From c31ec7dbd539dce46f9cf4bd843fc52be97f64a0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 17 Feb 2022 10:02:42 -0800 Subject: [PATCH] Adds setup view --- .../migrations/0136_auto_20220217_1708.py | 24 +++++++++++++++++++ bookwyrm/models/site.py | 5 ++++ bookwyrm/urls.py | 2 ++ bookwyrm/views/__init__.py | 1 + bookwyrm/views/setup.py | 18 ++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 bookwyrm/migrations/0136_auto_20220217_1708.py create mode 100644 bookwyrm/views/setup.py diff --git a/bookwyrm/migrations/0136_auto_20220217_1708.py b/bookwyrm/migrations/0136_auto_20220217_1708.py new file mode 100644 index 000000000..916fb124c --- /dev/null +++ b/bookwyrm/migrations/0136_auto_20220217_1708.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.12 on 2022-02-17 17:08 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0135_auto_20220217_1624"), + ] + + operations = [ + migrations.AddField( + model_name="sitesettings", + name="admin_code", + field=models.CharField(default=uuid.uuid4, max_length=50), + ), + migrations.AddField( + model_name="sitesettings", + name="install_mode", + field=models.BooleanField(default=False), + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index b2119e238..777792ed0 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -1,6 +1,7 @@ """ the particulars for this instance of BookWyrm """ import datetime from urllib.parse import urljoin +import uuid from django.db import models, IntegrityError from django.dispatch import receiver @@ -24,6 +25,10 @@ class SiteSettings(models.Model): instance_description = models.TextField(default="This instance has no description.") instance_short_description = models.CharField(max_length=255, blank=True, null=True) + # admin setup options + install_mode = models.BooleanField(default=False) + admin_code = models.CharField(max_length=50, default=uuid.uuid4) + # about page registration_closed_text = models.TextField( default="We aren't taking new users at this time. You can find an open " diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 5ee09a3a4..bac1d9b49 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -58,6 +58,8 @@ urlpatterns = [ views.get_unread_status_string, name="stream-updates", ), + # instance setup + re_path(r"^setup/?$", views.CreateAdmin.as_view(), name="setup-admin"), # authentication re_path(r"^login/?$", views.Login.as_view(), name="login"), re_path(r"^login/(?Pconfirmed)/?$", views.Login.as_view(), name="login"), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 579e89cbc..9da49c73c 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -113,6 +113,7 @@ from .reading import ReadingStatus from .report import Report from .rss_feed import RssFeed from .search import Search +from .setup import CreateAdmin from .status import CreateStatus, EditStatus, DeleteStatus, update_progress from .status import edit_readthrough from .updates import get_notification_count, get_unread_status_string diff --git a/bookwyrm/views/setup.py b/bookwyrm/views/setup.py new file mode 100644 index 000000000..be3fb0a32 --- /dev/null +++ b/bookwyrm/views/setup.py @@ -0,0 +1,18 @@ +""" Installation wizard 🧙 """ +from django.template.response import TemplateResponse +from django.utils.decorators import method_decorator +from django.views import View + +from bookwyrm import emailing, forms, models + + +# pylint: disable= no-self-use +class CreateAdmin(View): + """manage things like the instance name""" + + def get(self, request): + """Create admin user""" + data = { + "register_form": forms.RegisterForm() + } + return TemplateResponse(request, "setup/admin.html", data)