From e15193e1000193a64742b91c02688b78c2eaec58 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 26 Feb 2022 12:43:27 -0800 Subject: [PATCH 01/33] Adds themes --- .../migrations/0142_auto_20220226_2024.py | 73 +++++++++++++++++++ bookwyrm/models/site.py | 27 +++++++ .../{themes/dark.scss => bookwyrm-dark.scss} | 0 .../light.scss => bookwyrm-light.scss} | 4 +- bookwyrm/static/css/bookwyrm.scss | 1 - bookwyrm/templates/layout.html | 2 +- bookwyrm/templates/settings/site.html | 43 +++++++---- 7 files changed, 133 insertions(+), 17 deletions(-) create mode 100644 bookwyrm/migrations/0142_auto_20220226_2024.py rename bookwyrm/static/css/{themes/dark.scss => bookwyrm-dark.scss} (100%) rename bookwyrm/static/css/{themes/light.scss => bookwyrm-light.scss} (93%) diff --git a/bookwyrm/migrations/0142_auto_20220226_2024.py b/bookwyrm/migrations/0142_auto_20220226_2024.py new file mode 100644 index 00000000..662cd9bd --- /dev/null +++ b/bookwyrm/migrations/0142_auto_20220226_2024.py @@ -0,0 +1,73 @@ +# Generated by Django 3.2.12 on 2022-02-26 20:24 + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +def add_default_themes(apps, schema_editor): + """add light and dark themes""" + db_alias = schema_editor.connection.alias + theme_model = apps.get_model("bookwyrm", "Theme") + theme_model.objects.using(db_alias).bulk_create( + [ + theme_model.objects.using(db_alias)( + name="BookWyrm Light", + path="bookwyrm-light.scss", + ), + theme_model.objects.using(db_alias)( + name="BookWyrm Dark", + path="bookwyrm-dark.scss", + ), + ] + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0141_alter_report_status"), + ] + + operations = [ + migrations.CreateModel( + name="Theme", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created_date", models.DateTimeField(auto_now_add=True)), + ("name", models.CharField(max_length=10, unique=True)), + ( + "theme_file", + models.FileField( + upload_to="css/", + validators=[ + django.core.validators.FileExtensionValidator( + ["scss", "sass"] + ) + ], + ), + ), + ], + ), + migrations.AddField( + model_name="sitesettings", + name="default_theme", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="bookwyrm.theme", + ), + ), + migrations.RunPython( + add_default_themes, reversed_code=migrations.RunPython.noop + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index a40d295b..602a3f59 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -3,6 +3,7 @@ import datetime from urllib.parse import urljoin import uuid +from django.core.validators import FileExtensionValidator from django.db import models, IntegrityError from django.dispatch import receiver from django.utils import timezone @@ -24,6 +25,9 @@ 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) + default_theme = models.ForeignKey( + "Theme", null=True, blank=True, on_delete=models.SET_NULL + ) # admin setup options install_mode = models.BooleanField(default=False) @@ -104,6 +108,29 @@ class SiteSettings(models.Model): super().save(*args, **kwargs) +class Theme(models.Model): + """Theme files""" + + created_date = models.DateTimeField(auto_now_add=True) + name = models.CharField(max_length=10, unique=True) + theme_file = models.FileField( + upload_to="css/", + validators=[FileExtensionValidator(["scss", "sass"])], + null=True, + ) + path = models.CharField(max_length=50, blank=True, null=True) + + @classmethod + def get_theme(cls, user): + """get the theme given the user/site""" + if user and user.theme: + return user.theme.path + site = SiteSettings.objects.get() + if site.theme: + return site.theme.path + return "light.scss" + + class SiteInvite(models.Model): """gives someone access to create an account on the instance""" diff --git a/bookwyrm/static/css/themes/dark.scss b/bookwyrm/static/css/bookwyrm-dark.scss similarity index 100% rename from bookwyrm/static/css/themes/dark.scss rename to bookwyrm/static/css/bookwyrm-dark.scss diff --git a/bookwyrm/static/css/themes/light.scss b/bookwyrm/static/css/bookwyrm-light.scss similarity index 93% rename from bookwyrm/static/css/themes/light.scss rename to bookwyrm/static/css/bookwyrm-light.scss index 339fc2c3..6b7b5b34 100644 --- a/bookwyrm/static/css/themes/light.scss +++ b/bookwyrm/static/css/bookwyrm-light.scss @@ -1,4 +1,4 @@ -@import "../vendor/bulma/sass/utilities/derived-variables.sass"; +@import "vendor/bulma/sass/utilities/derived-variables.sass"; /* Colors ******************************************************************************/ @@ -51,3 +51,5 @@ $menu-item-active-background-color: $link-background; ******************************************************************************/ $family-primary: $family-sans-serif; $family-secondary: $family-sans-serif; + +@import "bookwyrm.scss"; diff --git a/bookwyrm/static/css/bookwyrm.scss b/bookwyrm/static/css/bookwyrm.scss index 6b5e7e6b..ee25b728 100644 --- a/bookwyrm/static/css/bookwyrm.scss +++ b/bookwyrm/static/css/bookwyrm.scss @@ -1,7 +1,6 @@ @charset "utf-8"; @import "instance-settings"; -@import "themes/light.scss"; @import "vendor/bulma/bulma.sass"; @import "vendor/icons.css"; @import "bookwyrm/all.scss"; diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 0e874072..a3149996 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -8,7 +8,7 @@ {% block title %}BookWyrm{% endblock %} - {{ site.name }} - + diff --git a/bookwyrm/templates/settings/site.html b/bookwyrm/templates/settings/site.html index 2ecd988e..0afbd64f 100644 --- a/bookwyrm/templates/settings/site.html +++ b/bookwyrm/templates/settings/site.html @@ -8,7 +8,7 @@ {% block site-subtabs %} @@ -68,20 +68,35 @@ -
-

{% trans "Images" %}

-
-
- - {{ site_form.logo }} +
+

{% trans "Display" %}

+
+

{% trans "Images" %}

+
+
+ + {{ site_form.logo }} +
+
+ + {{ site_form.logo_small }} +
+
+ + {{ site_form.favicon }} +
-
- - {{ site_form.logo_small }} -
-
- - {{ site_form.favicon }} + +

{% trans "Themes" %}

+
+ +
+ {{ site_form.default_theme }} +
+ +
From 43269429acdec88d1c369a142543d124ef060427 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 26 Feb 2022 13:38:45 -0800 Subject: [PATCH 02/33] Use selected theme --- ...226_2024.py => 0142_auto_20220226_2047.py} | 36 +++++++++++-------- bookwyrm/models/__init__.py | 2 +- bookwyrm/models/site.py | 16 ++++----- bookwyrm/models/user.py | 14 ++++++++ bookwyrm/static/css/bookwyrm-dark.scss | 4 ++- bookwyrm/templates/layout.html | 4 ++- 6 files changed, 50 insertions(+), 26 deletions(-) rename bookwyrm/migrations/{0142_auto_20220226_2024.py => 0142_auto_20220226_2047.py} (67%) diff --git a/bookwyrm/migrations/0142_auto_20220226_2024.py b/bookwyrm/migrations/0142_auto_20220226_2047.py similarity index 67% rename from bookwyrm/migrations/0142_auto_20220226_2024.py rename to bookwyrm/migrations/0142_auto_20220226_2047.py index 662cd9bd..928d556c 100644 --- a/bookwyrm/migrations/0142_auto_20220226_2024.py +++ b/bookwyrm/migrations/0142_auto_20220226_2047.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.12 on 2022-02-26 20:24 +# Generated by Django 3.2.12 on 2022-02-26 20:47 import django.core.validators from django.db import migrations, models @@ -9,17 +9,13 @@ def add_default_themes(apps, schema_editor): """add light and dark themes""" db_alias = schema_editor.connection.alias theme_model = apps.get_model("bookwyrm", "Theme") - theme_model.objects.using(db_alias).bulk_create( - [ - theme_model.objects.using(db_alias)( - name="BookWyrm Light", - path="bookwyrm-light.scss", - ), - theme_model.objects.using(db_alias)( - name="BookWyrm Dark", - path="bookwyrm-dark.scss", - ), - ] + theme_model.objects.using(db_alias).create( + name="BookWyrm Light", + path="bookwyrm-light.scss", + ) + theme_model.objects.using(db_alias).create( + name="BookWyrm Dark", + path="bookwyrm-dark.scss", ) @@ -43,10 +39,11 @@ class Migration(migrations.Migration): ), ), ("created_date", models.DateTimeField(auto_now_add=True)), - ("name", models.CharField(max_length=10, unique=True)), + ("name", models.CharField(max_length=50, unique=True)), ( "theme_file", models.FileField( + null=True, upload_to="css/", validators=[ django.core.validators.FileExtensionValidator( @@ -55,6 +52,7 @@ class Migration(migrations.Migration): ], ), ), + ("path", models.CharField(blank=True, max_length=50, null=True)), ], ), migrations.AddField( @@ -67,7 +65,17 @@ class Migration(migrations.Migration): to="bookwyrm.theme", ), ), + migrations.AddField( + model_name="user", + name="theme", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="bookwyrm.theme", + ), + ), migrations.RunPython( - add_default_themes, reversed_code=migrations.RunPython.noop + add_default_themes, reverse_code=migrations.RunPython.noop ), ] diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index 440d18d9..a8a84f09 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -26,7 +26,7 @@ from .group import Group, GroupMember, GroupMemberInvitation from .import_job import ImportJob, ImportItem -from .site import SiteSettings, SiteInvite +from .site import SiteSettings, Theme, SiteInvite from .site import PasswordReset, InviteRequest from .announcement import Announcement from .antispam import EmailBlocklist, IPBlocklist, AutoMod, automod_task diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index 602a3f59..30ebfe74 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -112,7 +112,7 @@ class Theme(models.Model): """Theme files""" created_date = models.DateTimeField(auto_now_add=True) - name = models.CharField(max_length=10, unique=True) + name = models.CharField(max_length=50, unique=True) theme_file = models.FileField( upload_to="css/", validators=[FileExtensionValidator(["scss", "sass"])], @@ -120,15 +120,13 @@ class Theme(models.Model): ) path = models.CharField(max_length=50, blank=True, null=True) - @classmethod - def get_theme(cls, user): + def __str__(self): + return self.name + + @property + def theme_path(self): """get the theme given the user/site""" - if user and user.theme: - return user.theme.path - site = SiteSettings.objects.get() - if site.theme: - return site.theme.path - return "light.scss" + return self.theme_file.path if self.theme_file else self.path class SiteInvite(models.Model): diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 6367dcae..3d12e604 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -136,6 +136,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): updated_date = models.DateTimeField(auto_now=True) last_active_date = models.DateTimeField(default=timezone.now) manually_approves_followers = fields.BooleanField(default=False) + theme = models.ForeignKey("Theme", null=True, blank=True, on_delete=models.SET_NULL) # options to turn features on and off show_goal = models.BooleanField(default=True) @@ -172,6 +173,19 @@ class User(OrderedCollectionPageMixin, AbstractUser): property_fields = [("following_link", "following")] field_tracker = FieldTracker(fields=["name", "avatar"]) + @property + def get_theme(self): + """get the theme given the user/site""" + if self.theme: + path = self.theme.theme_path + else: + site_model = apps.get_model("bookwyrm", "SiteSettings", require_ready=True) + site = site_model.objects.get() + if site.default_theme: + path = site.default_theme.theme_path + path = path or "light.scss" + return f"css/{path}" + @property def confirmation_link(self): """helper for generating confirmation links""" diff --git a/bookwyrm/static/css/bookwyrm-dark.scss b/bookwyrm/static/css/bookwyrm-dark.scss index 8df4ce50..957187ff 100644 --- a/bookwyrm/static/css/bookwyrm-dark.scss +++ b/bookwyrm/static/css/bookwyrm-dark.scss @@ -1,4 +1,4 @@ -@import "../vendor/bulma/sass/utilities/derived-variables.sass"; +@import "vendor/bulma/sass/utilities/derived-variables.sass"; /* Colors ******************************************************************************/ @@ -53,3 +53,5 @@ $menu-item-active-background-color: $link-background; ******************************************************************************/ $family-primary: $family-sans-serif; $family-secondary: $family-sans-serif; + +@import "bookwyrm.scss"; diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index a3149996..444241e5 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -8,7 +8,9 @@ {% block title %}BookWyrm{% endblock %} - {{ site.name }} - + {% with theme_path=user.get_theme %} + + {% endwith %} From 40319302b76f0f542ec15494c191c4465a625714 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Sun, 27 Feb 2022 05:20:29 -0800 Subject: [PATCH 03/33] Initial theme --- bookwyrm/static/css/bookwyrm/_all.scss | 2 +- .../css/bookwyrm/components/_details.scss | 2 +- .../css/bookwyrm/components/_toggle.scss | 2 +- bookwyrm/static/css/themes/dark.scss | 51 ++++++++++++++----- bookwyrm/static/css/themes/light.scss | 3 ++ 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/bookwyrm/static/css/bookwyrm/_all.scss b/bookwyrm/static/css/bookwyrm/_all.scss index 11d7e403..f01cec60 100644 --- a/bookwyrm/static/css/bookwyrm/_all.scss +++ b/bookwyrm/static/css/bookwyrm/_all.scss @@ -115,7 +115,7 @@ button .button-invisible-overlay { align-items: center; flex-direction: column; justify-content: center; - background: rgba($scheme-invert, 0.66); + background: $invisible-overlay-background-color; color: white; opacity: 0; transition: opacity 0.2s ease; diff --git a/bookwyrm/static/css/bookwyrm/components/_details.scss b/bookwyrm/static/css/bookwyrm/components/_details.scss index 645de4a1..5708c946 100644 --- a/bookwyrm/static/css/bookwyrm/components/_details.scss +++ b/bookwyrm/static/css/bookwyrm/components/_details.scss @@ -53,7 +53,7 @@ details.dropdown .dropdown-menu a:focus-visible { @media only screen and (max-width: 768px) { details.dropdown[open] summary.dropdown-trigger::before { - background-color: rgba($scheme-invert, 0.5); + background-color: $modal-background-background-color; z-index: 30; } diff --git a/bookwyrm/static/css/bookwyrm/components/_toggle.scss b/bookwyrm/static/css/bookwyrm/components/_toggle.scss index c2c07dfb..74d7f0d9 100644 --- a/bookwyrm/static/css/bookwyrm/components/_toggle.scss +++ b/bookwyrm/static/css/bookwyrm/components/_toggle.scss @@ -3,7 +3,7 @@ .toggle-button[aria-pressed="true"], .toggle-button[aria-pressed="true"]:hover { - background-color: hsl(171deg, 100%, 41%); + background-color: $primary; color: white; } diff --git a/bookwyrm/static/css/themes/dark.scss b/bookwyrm/static/css/themes/dark.scss index 8df4ce50..30ca12b1 100644 --- a/bookwyrm/static/css/themes/dark.scss +++ b/bookwyrm/static/css/themes/dark.scss @@ -1,24 +1,30 @@ -@import "../vendor/bulma/sass/utilities/derived-variables.sass"; +@import "../vendor/bulma/sass/utilities/initial-variables.sass"; /* Colors ******************************************************************************/ /* states */ -$primary: #016a5b; +$primary: #005e50; +$primary-light: #1d2b28; $info: #1f4666; $success: #246447; $warning: #8b6c15; $danger: #872538; +$danger-light: #481922; +$light: #393939; /* book cover standins */ $no-cover-color: #002549; /* background colors */ -$scheme-main: $grey-darker; -$scheme-main-bis: $black-ter; -$background-body: $grey-darker; -$background-secondary: $grey-dark; -$background-tertiary: #555; +$scheme-main: rgb(24, 27, 28); +$scheme-invert: #fff; +$scheme-main-bis: rgb(28, 30, 32); +$scheme-main-ter: rgb(32, 34, 36); +$background-body: rgb(24, 27, 28); +$background-secondary: rgb(28, 30, 32); +$background-tertiary: rgb(32, 34, 36); +$modal-background-background-color: rgba($black, 0.8); /* highlight colors */ $primary-highlight: $primary; @@ -26,10 +32,9 @@ $info-highlight: $info; $success-highlight: $success; /* borders */ -$border: $grey; -$border-hover: $grey-light; -$border-light: $grey; -$border-light-hover: $grey-light; +$border: #2b3031; +$border-light: #444; +$border-hover: #51595d; /* text */ $text: $grey-lightest; @@ -37,17 +42,35 @@ $text-light: $grey-lighter; $text-strong: $white-ter; /* links */ -$link: $white; +$link: #2e7eb9; $link-background: $background-tertiary; $link-hover: $white-bis; +$link-hover-border: #51595d; $link-focus: $white-bis; $link-active: $white-bis; -/* misc */ - /* bulma overrides */ $background: $background-secondary; $menu-item-active-background-color: $link-background; +$navbar-dropdown-item-hover-color: $white; + +/* These element's colors are hardcoded, probably a bug in bulma? */ +@media screen and (min-width: 769px) { + .navbar-dropdown { + box-shadow: 0 8px 8px rgba($black, 0.2) !important; + } +} + +@media screen and (max-width: 768px) { + .navbar-menu { + box-shadow: 0 8px 8px rgba($black, 0.2) !important; + } +} + +/* misc */ +$shadow: 0 0.5em 1em -0.125em rgba($black, 0.2), 0 0px 0 1px rgba($black, 0.02); +$card-header-shadow: 0 0.125em 0.25em rgba($black, 0.1); +$invisible-overlay-background-color: rgba($black, 0.66); /* Fonts ******************************************************************************/ diff --git a/bookwyrm/static/css/themes/light.scss b/bookwyrm/static/css/themes/light.scss index 339fc2c3..60781ff5 100644 --- a/bookwyrm/static/css/themes/light.scss +++ b/bookwyrm/static/css/themes/light.scss @@ -47,6 +47,9 @@ $link-active: $grey-darker; $background: $background-secondary; $menu-item-active-background-color: $link-background; +/* misc */ +$invisible-overlay-background-color: rgba($scheme-invert, 0.66); + /* Fonts ******************************************************************************/ $family-primary: $family-sans-serif; From e4d7dd7ee4c21af9d78eb806a5b5a7dd61849077 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Sun, 27 Feb 2022 05:29:33 -0800 Subject: [PATCH 04/33] Fix progress bar --- bookwyrm/static/css/themes/dark.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/static/css/themes/dark.scss b/bookwyrm/static/css/themes/dark.scss index 30ca12b1..c24e153e 100644 --- a/bookwyrm/static/css/themes/dark.scss +++ b/bookwyrm/static/css/themes/dark.scss @@ -71,6 +71,7 @@ $navbar-dropdown-item-hover-color: $white; $shadow: 0 0.5em 1em -0.125em rgba($black, 0.2), 0 0px 0 1px rgba($black, 0.02); $card-header-shadow: 0 0.125em 0.25em rgba($black, 0.1); $invisible-overlay-background-color: rgba($black, 0.66); +$progress-value-background-color: $border-light; /* Fonts ******************************************************************************/ From 6e96c1eee7d525845bafc4c89828ac68bdf232f9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 27 Feb 2022 08:09:17 -0800 Subject: [PATCH 05/33] Avoid linter error --- bookwyrm/models/site.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index 30ebfe74..13cfdc75 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -121,6 +121,7 @@ class Theme(models.Model): path = models.CharField(max_length=50, blank=True, null=True) def __str__(self): + # pylint: disable=invalid-str-returned return self.name @property From 3dfbb3272e35877400da907d4d958ea8554b995a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 27 Feb 2022 10:00:50 -0800 Subject: [PATCH 06/33] Theme selector --- bookwyrm/forms.py | 18 +++ ...226_2047.py => 0142_auto_20220227_1752.py} | 17 +-- bookwyrm/models/site.py | 13 +-- bookwyrm/models/user.py | 6 +- bookwyrm/templates/settings/layout.html | 4 + bookwyrm/templates/settings/site.html | 9 +- bookwyrm/templates/settings/themes.html | 109 ++++++++++++++++++ bookwyrm/urls.py | 1 + bookwyrm/views/__init__.py | 1 + bookwyrm/views/admin/site.py | 2 +- bookwyrm/views/admin/themes.py | 38 ++++++ 11 files changed, 184 insertions(+), 34 deletions(-) rename bookwyrm/migrations/{0142_auto_20220226_2047.py => 0142_auto_20220227_1752.py} (76%) create mode 100644 bookwyrm/templates/settings/themes.html create mode 100644 bookwyrm/views/admin/themes.py diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 7ae4e446..926aaecf 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -454,6 +454,24 @@ class SiteForm(CustomForm): } +class SiteThemeForm(CustomForm): + class Meta: + model = models.SiteSettings + fields = ["default_theme"] + + +class ThemeForm(CustomForm): + class Meta: + model = models.Theme + fields = ["name", "path"] + widgets = { + "name": forms.TextInput(attrs={"aria-describedby": "desc_name"}), + "path": ClearableFileInputWithWarning( + attrs={"aria-describedby": "desc_path"} + ), + } + + class AnnouncementForm(CustomForm): class Meta: model = models.Announcement diff --git a/bookwyrm/migrations/0142_auto_20220226_2047.py b/bookwyrm/migrations/0142_auto_20220227_1752.py similarity index 76% rename from bookwyrm/migrations/0142_auto_20220226_2047.py rename to bookwyrm/migrations/0142_auto_20220227_1752.py index 928d556c..75f0e1e7 100644 --- a/bookwyrm/migrations/0142_auto_20220226_2047.py +++ b/bookwyrm/migrations/0142_auto_20220227_1752.py @@ -1,6 +1,5 @@ -# Generated by Django 3.2.12 on 2022-02-26 20:47 +# Generated by Django 3.2.12 on 2022-02-27 17:52 -import django.core.validators from django.db import migrations, models import django.db.models.deletion @@ -40,19 +39,7 @@ class Migration(migrations.Migration): ), ("created_date", models.DateTimeField(auto_now_add=True)), ("name", models.CharField(max_length=50, unique=True)), - ( - "theme_file", - models.FileField( - null=True, - upload_to="css/", - validators=[ - django.core.validators.FileExtensionValidator( - ["scss", "sass"] - ) - ], - ), - ), - ("path", models.CharField(blank=True, max_length=50, null=True)), + ("path", models.CharField(max_length=50, unique=True)), ], ), migrations.AddField( diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index 13cfdc75..c6c53f76 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -3,7 +3,6 @@ import datetime from urllib.parse import urljoin import uuid -from django.core.validators import FileExtensionValidator from django.db import models, IntegrityError from django.dispatch import receiver from django.utils import timezone @@ -113,22 +112,12 @@ class Theme(models.Model): created_date = models.DateTimeField(auto_now_add=True) name = models.CharField(max_length=50, unique=True) - theme_file = models.FileField( - upload_to="css/", - validators=[FileExtensionValidator(["scss", "sass"])], - null=True, - ) - path = models.CharField(max_length=50, blank=True, null=True) + path = models.CharField(max_length=50, unique=True) def __str__(self): # pylint: disable=invalid-str-returned return self.name - @property - def theme_path(self): - """get the theme given the user/site""" - return self.theme_file.path if self.theme_file else self.path - class SiteInvite(models.Model): """gives someone access to create an account on the instance""" diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 3d12e604..85702ae5 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -176,14 +176,14 @@ class User(OrderedCollectionPageMixin, AbstractUser): @property def get_theme(self): """get the theme given the user/site""" + path = "bookwyrm-light.scss" if self.theme: - path = self.theme.theme_path + path = self.theme.path else: site_model = apps.get_model("bookwyrm", "SiteSettings", require_ready=True) site = site_model.objects.get() if site.default_theme: - path = site.default_theme.theme_path - path = path or "light.scss" + path = site.default_theme.path return f"css/{path}" @property diff --git a/bookwyrm/templates/settings/layout.html b/bookwyrm/templates/settings/layout.html index c5a3c5af..d76c954d 100644 --- a/bookwyrm/templates/settings/layout.html +++ b/bookwyrm/templates/settings/layout.html @@ -86,6 +86,10 @@ {% trans "Site Settings" %} {% block site-subtabs %}{% endblock %} +
  • + {% url 'settings-themes' as url %} + {% trans "Themes" %} +
  • {% endif %} diff --git a/bookwyrm/templates/settings/site.html b/bookwyrm/templates/settings/site.html index 0afbd64f..4d9dbe40 100644 --- a/bookwyrm/templates/settings/site.html +++ b/bookwyrm/templates/settings/site.html @@ -33,7 +33,12 @@
    {% endif %} -
    + {% csrf_token %}

    {% trans "Instance Info" %}

    @@ -95,8 +100,6 @@
    {{ site_form.default_theme }}
    - -
    diff --git a/bookwyrm/templates/settings/themes.html b/bookwyrm/templates/settings/themes.html new file mode 100644 index 00000000..6e9eb61c --- /dev/null +++ b/bookwyrm/templates/settings/themes.html @@ -0,0 +1,109 @@ +{% extends 'settings/layout.html' %} +{% load i18n %} + +{% block title %}{% trans "Themes" %}{% endblock %} + +{% block header %}{% trans "Themes" %}{% endblock %} + +{% block panel %} +{% if success %} +
    + + + {% trans "Successfully added theme" %} + +
    +{% endif %} + +
    +
    +

    + {% trans "Default theme:" %} {{ site.default_theme.name }} +

    + +

    + + {% trans "Set default theme" %} + +

    +
    +
    + +
    +

    {% trans "Upload theme" %}

    + + {% if theme_form.errors %} +
    + + + {% trans "Unable to save theme" %} + +
    + {% endif %} + + + {% csrf_token %} +
    +
    + +
    + {{ theme_form.name }} + {% include 'snippets/form_errors.html' with errors_list=theme_form.name.errors id="desc_name" %} +
    +
    + +
    + +
    + {{ theme_form.theme_file }} + {% include 'snippets/form_errors.html' with errors_list=theme_form.theme_file.errors id="desc_theme_file" %} +
    +
    +
    + + + +
    + +
    +

    {% trans "Available Themes" %}

    +
    + + + + + + + {% for theme in themes %} + + + + + + {% endfor %} +
    + {% trans "Theme name" %} + + {% trans "File" %} + + {% trans "Actions" %} +
    {{ theme.name }}{{ theme.theme_path }} + {% if theme.theme_file %} +
    + +
    + {% endif %} +
    +
    +
    + +{% endblock %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index d2caa76e..bef6786d 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -86,6 +86,7 @@ urlpatterns = [ r"^settings/dashboard/?$", views.Dashboard.as_view(), name="settings-dashboard" ), re_path(r"^settings/site-settings/?$", views.Site.as_view(), name="settings-site"), + re_path(r"^settings/themes/?$", views.Themes.as_view(), name="settings-themes"), re_path( r"^settings/announcements/?$", views.Announcements.as_view(), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 76e9ff02..675221cb 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -21,6 +21,7 @@ from .admin.reports import ( moderator_delete_user, ) from .admin.site import Site +from .admin.themes import Themes from .admin.user_admin import UserAdmin, UserAdminList # user preferences diff --git a/bookwyrm/views/admin/site.py b/bookwyrm/views/admin/site.py index 7e75a820..f345d997 100644 --- a/bookwyrm/views/admin/site.py +++ b/bookwyrm/views/admin/site.py @@ -29,7 +29,7 @@ class Site(View): if not form.is_valid(): data = {"site_form": form} return TemplateResponse(request, "settings/site.html", data) - form.save() + site = form.save() data = {"site_form": forms.SiteForm(instance=site), "success": True} return TemplateResponse(request, "settings/site.html", data) diff --git a/bookwyrm/views/admin/themes.py b/bookwyrm/views/admin/themes.py new file mode 100644 index 00000000..cf11bc6d --- /dev/null +++ b/bookwyrm/views/admin/themes.py @@ -0,0 +1,38 @@ +""" manage themes """ +from django.contrib.auth.decorators import login_required, permission_required +from django.template.response import TemplateResponse +from django.utils.decorators import method_decorator +from django.views import View + +from bookwyrm import forms, models + + +# pylint: disable= no-self-use +@method_decorator(login_required, name="dispatch") +@method_decorator( + permission_required("bookwyrm.edit_instance_settings", raise_exception=True), + name="dispatch", +) +class Themes(View): + """manage things like the instance name""" + + def get(self, request): + """view existing themes and set defaults""" + data = { + "themes": models.Theme.objects.all(), + "theme_form": forms.ThemeForm(), + } + return TemplateResponse(request, "settings/themes.html", data) + + def post(self, request): + """edit the site settings""" + form = forms.ThemeForm(request.POST, request.FILES) + data = { + "themes": models.Theme.objects.all(), + "theme_form": form, + } + if form.is_valid(): + form.save() + data["success"] = True + data["theme_form"] = forms.ThemeForm() + return TemplateResponse(request, "settings/themes.html", data) From cc015536faff14908017da89cdcb98e47b4c74e6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 27 Feb 2022 10:12:47 -0800 Subject: [PATCH 07/33] Adds theme instructions --- bookwyrm/forms.py | 4 +-- bookwyrm/templates/settings/themes.html | 41 +++++++++++++------------ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 926aaecf..4e6bab16 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -466,9 +466,7 @@ class ThemeForm(CustomForm): fields = ["name", "path"] widgets = { "name": forms.TextInput(attrs={"aria-describedby": "desc_name"}), - "path": ClearableFileInputWithWarning( - attrs={"aria-describedby": "desc_path"} - ), + "path": forms.TextInput(attrs={"aria-describedby": "desc_path", "placeholder": _("example-theme.scss")}), } diff --git a/bookwyrm/templates/settings/themes.html b/bookwyrm/templates/settings/themes.html index 6e9eb61c..3eac261d 100644 --- a/bookwyrm/templates/settings/themes.html +++ b/bookwyrm/templates/settings/themes.html @@ -16,21 +16,24 @@ {% endif %}
    -
    -

    - {% trans "Default theme:" %} {{ site.default_theme.name }} -

    - -

    - - {% trans "Set default theme" %} - -

    +
    +

    {% trans "How to add a theme" %}

    +
      +
    1. + {% trans "Copy the theme file into the bookwyrm/static/css/ directory on your server from the command line." %} +
    2. +
    3. + {% trans "Run ./bw-dev compilescss." %} +
    4. +
    5. + {% trans "Add the file name using the form below to make it available in the application interface." %} +
    6. +
    -

    {% trans "Upload theme" %}

    +

    {% trans "Add theme" %}

    {% if theme_form.errors %}
    @@ -60,17 +63,17 @@
    -
    - +
    @@ -92,13 +95,11 @@ {% for theme in themes %} {{ theme.name }} - {{ theme.theme_path }} + {{ theme.path }} - {% if theme.theme_file %}
    - +
    - {% endif %} {% endfor %} From 8850b68b5224db3ade4cb9606bf66f11eb442e6a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 27 Feb 2022 10:46:01 -0800 Subject: [PATCH 08/33] Show theme options --- bookwyrm/forms.py | 13 ++++++++++++- bookwyrm/migrations/0142_auto_20220227_1752.py | 4 ++-- bookwyrm/models/user.py | 14 ++++++-------- .../static/css/{ => themes}/bookwyrm-dark.scss | 4 ++-- .../static/css/{ => themes}/bookwyrm-light.scss | 4 ++-- bookwyrm/templates/layout.html | 2 +- bookwyrm/templates/settings/themes.html | 6 ++++-- 7 files changed, 29 insertions(+), 18 deletions(-) rename bookwyrm/static/css/{ => themes}/bookwyrm-dark.scss (92%) rename bookwyrm/static/css/{ => themes}/bookwyrm-light.scss (92%) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 4e6bab16..81061f96 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -4,6 +4,8 @@ from collections import defaultdict from urllib.parse import urlparse from django import forms +from django.contrib.staticfiles.utils import get_files +from django.contrib.staticfiles.storage import StaticFilesStorage from django.forms import ModelForm, PasswordInput, widgets, ChoiceField from django.forms.widgets import Textarea from django.utils import timezone @@ -460,13 +462,22 @@ class SiteThemeForm(CustomForm): fields = ["default_theme"] +def get_theme_choices(): + """static files""" + choices = list(get_files(StaticFilesStorage(), location="css/themes")) + current = models.Theme.objects.values_list("path", flat=True) + return [(c, c) for c in choices if c not in current and c[-5:] == ".scss"] + + class ThemeForm(CustomForm): class Meta: model = models.Theme fields = ["name", "path"] widgets = { "name": forms.TextInput(attrs={"aria-describedby": "desc_name"}), - "path": forms.TextInput(attrs={"aria-describedby": "desc_path", "placeholder": _("example-theme.scss")}), + "path": forms.Select( + attrs={"aria-describedby": "desc_path"}, choices=get_theme_choices() + ), } diff --git a/bookwyrm/migrations/0142_auto_20220227_1752.py b/bookwyrm/migrations/0142_auto_20220227_1752.py index 75f0e1e7..2282679d 100644 --- a/bookwyrm/migrations/0142_auto_20220227_1752.py +++ b/bookwyrm/migrations/0142_auto_20220227_1752.py @@ -10,11 +10,11 @@ def add_default_themes(apps, schema_editor): theme_model = apps.get_model("bookwyrm", "Theme") theme_model.objects.using(db_alias).create( name="BookWyrm Light", - path="bookwyrm-light.scss", + path="css/themes/bookwyrm-light.scss", ) theme_model.objects.using(db_alias).create( name="BookWyrm Dark", - path="bookwyrm-dark.scss", + path="css/themes/bookwyrm-dark.scss", ) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 85702ae5..1198717e 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -176,15 +176,13 @@ class User(OrderedCollectionPageMixin, AbstractUser): @property def get_theme(self): """get the theme given the user/site""" - path = "bookwyrm-light.scss" if self.theme: - path = self.theme.path - else: - site_model = apps.get_model("bookwyrm", "SiteSettings", require_ready=True) - site = site_model.objects.get() - if site.default_theme: - path = site.default_theme.path - return f"css/{path}" + return self.theme.path + site_model = apps.get_model("bookwyrm", "SiteSettings", require_ready=True) + site = site_model.objects.get() + if site.default_theme: + return site.default_theme.path + return "css/themes/bookwyrm-light.scss" @property def confirmation_link(self): diff --git a/bookwyrm/static/css/bookwyrm-dark.scss b/bookwyrm/static/css/themes/bookwyrm-dark.scss similarity index 92% rename from bookwyrm/static/css/bookwyrm-dark.scss rename to bookwyrm/static/css/themes/bookwyrm-dark.scss index 957187ff..32e33907 100644 --- a/bookwyrm/static/css/bookwyrm-dark.scss +++ b/bookwyrm/static/css/themes/bookwyrm-dark.scss @@ -1,4 +1,4 @@ -@import "vendor/bulma/sass/utilities/derived-variables.sass"; +@import "../vendor/bulma/sass/utilities/derived-variables.sass"; /* Colors ******************************************************************************/ @@ -54,4 +54,4 @@ $menu-item-active-background-color: $link-background; $family-primary: $family-sans-serif; $family-secondary: $family-sans-serif; -@import "bookwyrm.scss"; +@import "../bookwyrm.scss"; diff --git a/bookwyrm/static/css/bookwyrm-light.scss b/bookwyrm/static/css/themes/bookwyrm-light.scss similarity index 92% rename from bookwyrm/static/css/bookwyrm-light.scss rename to bookwyrm/static/css/themes/bookwyrm-light.scss index 6b7b5b34..08e6a291 100644 --- a/bookwyrm/static/css/bookwyrm-light.scss +++ b/bookwyrm/static/css/themes/bookwyrm-light.scss @@ -1,4 +1,4 @@ -@import "vendor/bulma/sass/utilities/derived-variables.sass"; +@import "../vendor/bulma/sass/utilities/derived-variables.sass"; /* Colors ******************************************************************************/ @@ -52,4 +52,4 @@ $menu-item-active-background-color: $link-background; $family-primary: $family-sans-serif; $family-secondary: $family-sans-serif; -@import "bookwyrm.scss"; +@import "../bookwyrm.scss"; diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 444241e5..aaf21717 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -9,7 +9,7 @@ {% block title %}BookWyrm{% endblock %} - {{ site.name }} {% with theme_path=user.get_theme %} - + {% endwith %} diff --git a/bookwyrm/templates/settings/themes.html b/bookwyrm/templates/settings/themes.html index 3eac261d..a0619369 100644 --- a/bookwyrm/templates/settings/themes.html +++ b/bookwyrm/templates/settings/themes.html @@ -20,7 +20,7 @@

    {% trans "How to add a theme" %}

    1. - {% trans "Copy the theme file into the bookwyrm/static/css/ directory on your server from the command line." %} + {% trans "Copy the theme file into the bookwyrm/static/css/themes directory on your server from the command line." %}
    2. {% trans "Run ./bw-dev compilescss." %} @@ -67,7 +67,9 @@ {% trans "Theme filename" %}
      - {{ theme_form.path }} +
      + {{ theme_form.path }} +
      {% include 'snippets/form_errors.html' with errors_list=theme_form.path.errors id="desc_path" %}
      From fd0f7394182c864bd96244d92b81a1fa44cb3422 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 27 Feb 2022 10:51:49 -0800 Subject: [PATCH 09/33] Rename light.scss to bookwyrm-light.scss --- bookwyrm/static/css/themes/{light.scss => bookwyrm-light.scss} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bookwyrm/static/css/themes/{light.scss => bookwyrm-light.scss} (100%) diff --git a/bookwyrm/static/css/themes/light.scss b/bookwyrm/static/css/themes/bookwyrm-light.scss similarity index 100% rename from bookwyrm/static/css/themes/light.scss rename to bookwyrm/static/css/themes/bookwyrm-light.scss From c8d3222c33ffc918c71dcf5d74f6129d0981dc3b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 27 Feb 2022 10:52:07 -0800 Subject: [PATCH 10/33] Rename dark.scss to bookwyrm-dark.scss --- bookwyrm/static/css/themes/{dark.scss => bookwyrm-dark.scss} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bookwyrm/static/css/themes/{dark.scss => bookwyrm-dark.scss} (100%) diff --git a/bookwyrm/static/css/themes/dark.scss b/bookwyrm/static/css/themes/bookwyrm-dark.scss similarity index 100% rename from bookwyrm/static/css/themes/dark.scss rename to bookwyrm/static/css/themes/bookwyrm-dark.scss From 8259d16ee9b4b13fa6218f3ee8d374627a7b774b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 27 Feb 2022 11:19:09 -0800 Subject: [PATCH 11/33] Check available themes in form --- bookwyrm/forms.py | 13 +---------- bookwyrm/templates/settings/themes.html | 20 ++++++++++++++++- bookwyrm/views/admin/themes.py | 30 ++++++++++++++++--------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 81061f96..01228b8e 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -4,8 +4,6 @@ from collections import defaultdict from urllib.parse import urlparse from django import forms -from django.contrib.staticfiles.utils import get_files -from django.contrib.staticfiles.storage import StaticFilesStorage from django.forms import ModelForm, PasswordInput, widgets, ChoiceField from django.forms.widgets import Textarea from django.utils import timezone @@ -462,22 +460,13 @@ class SiteThemeForm(CustomForm): fields = ["default_theme"] -def get_theme_choices(): - """static files""" - choices = list(get_files(StaticFilesStorage(), location="css/themes")) - current = models.Theme.objects.values_list("path", flat=True) - return [(c, c) for c in choices if c not in current and c[-5:] == ".scss"] - - class ThemeForm(CustomForm): class Meta: model = models.Theme fields = ["name", "path"] widgets = { "name": forms.TextInput(attrs={"aria-describedby": "desc_name"}), - "path": forms.Select( - attrs={"aria-describedby": "desc_path"}, choices=get_theme_choices() - ), + "path": forms.Select(attrs={"aria-describedby": "desc_path"}), } diff --git a/bookwyrm/templates/settings/themes.html b/bookwyrm/templates/settings/themes.html index a0619369..11c34405 100644 --- a/bookwyrm/templates/settings/themes.html +++ b/bookwyrm/templates/settings/themes.html @@ -50,6 +50,12 @@ class="box" enctype="multipart/form-data" > + {% if not choices %} +
      + {% trans "No available theme files detected" %} +
      + {% endif %} +
      {% csrf_token %}
      @@ -68,7 +74,18 @@
      - {{ theme_form.path }} +
      {% include 'snippets/form_errors.html' with errors_list=theme_form.path.errors id="desc_path" %}
      @@ -76,6 +93,7 @@
      +
      diff --git a/bookwyrm/views/admin/themes.py b/bookwyrm/views/admin/themes.py index cf11bc6d..c1eacf44 100644 --- a/bookwyrm/views/admin/themes.py +++ b/bookwyrm/views/admin/themes.py @@ -1,5 +1,7 @@ """ manage themes """ from django.contrib.auth.decorators import login_required, permission_required +from django.contrib.staticfiles.utils import get_files +from django.contrib.staticfiles.storage import StaticFilesStorage from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View @@ -18,21 +20,29 @@ class Themes(View): def get(self, request): """view existing themes and set defaults""" - data = { - "themes": models.Theme.objects.all(), - "theme_form": forms.ThemeForm(), - } - return TemplateResponse(request, "settings/themes.html", data) + return TemplateResponse(request, "settings/themes.html", get_view_data()) def post(self, request): """edit the site settings""" form = forms.ThemeForm(request.POST, request.FILES) - data = { - "themes": models.Theme.objects.all(), - "theme_form": form, - } if form.is_valid(): form.save() + + data = get_view_data() + + if not form.is_valid(): + data["theme_form"] = form + else: data["success"] = True - data["theme_form"] = forms.ThemeForm() return TemplateResponse(request, "settings/themes.html", data) + + +def get_view_data(): + """data for view""" + choices = list(get_files(StaticFilesStorage(), location="css/themes")) + current = models.Theme.objects.values_list("path", flat=True) + return { + "themes": models.Theme.objects.all(), + "choices": [c for c in choices if c not in current and c[-5:] == ".scss"], + "theme_form": forms.ThemeForm(), + } From 4d3e709b2a425f0ac078ddaf39b70c72eb837a7f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 09:23:03 -0800 Subject: [PATCH 12/33] Update layout.html --- bookwyrm/templates/layout.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index aaf21717..444241e5 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -9,7 +9,7 @@ {% block title %}BookWyrm{% endblock %} - {{ site.name }} {% with theme_path=user.get_theme %} - + {% endwith %} From f5fb5ae04572b1ea6175c954ceb9ca64055a9521 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 09:34:30 -0800 Subject: [PATCH 13/33] Removes instance config file I'd be happy to re-add this if it's useful, but I think it's confusing to have in addition to themes --- .css-config-sample/_instance-settings.scss | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .css-config-sample/_instance-settings.scss diff --git a/.css-config-sample/_instance-settings.scss b/.css-config-sample/_instance-settings.scss deleted file mode 100644 index e86c1ce0..00000000 --- a/.css-config-sample/_instance-settings.scss +++ /dev/null @@ -1,3 +0,0 @@ -@charset "utf-8"; - -// Copy this file to bookwyrm/static/css/ and set your instance custom styles. From 2d516812b4a445e3b4e6dc562b6582fa52cdec04 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 09:34:54 -0800 Subject: [PATCH 14/33] Fixes icons by moving import to theme --- bookwyrm/static/css/bookwyrm.scss | 2 -- bookwyrm/static/css/themes/bookwyrm-dark.scss | 1 + bookwyrm/static/css/themes/bookwyrm-light.scss | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/static/css/bookwyrm.scss b/bookwyrm/static/css/bookwyrm.scss index ee25b728..43779545 100644 --- a/bookwyrm/static/css/bookwyrm.scss +++ b/bookwyrm/static/css/bookwyrm.scss @@ -1,6 +1,4 @@ @charset "utf-8"; -@import "instance-settings"; @import "vendor/bulma/bulma.sass"; -@import "vendor/icons.css"; @import "bookwyrm/all.scss"; diff --git a/bookwyrm/static/css/themes/bookwyrm-dark.scss b/bookwyrm/static/css/themes/bookwyrm-dark.scss index 32e33907..b2a6f582 100644 --- a/bookwyrm/static/css/themes/bookwyrm-dark.scss +++ b/bookwyrm/static/css/themes/bookwyrm-dark.scss @@ -55,3 +55,4 @@ $family-primary: $family-sans-serif; $family-secondary: $family-sans-serif; @import "../bookwyrm.scss"; +@import "../vendor/icons.css"; diff --git a/bookwyrm/static/css/themes/bookwyrm-light.scss b/bookwyrm/static/css/themes/bookwyrm-light.scss index 08e6a291..02992bff 100644 --- a/bookwyrm/static/css/themes/bookwyrm-light.scss +++ b/bookwyrm/static/css/themes/bookwyrm-light.scss @@ -53,3 +53,4 @@ $family-primary: $family-sans-serif; $family-secondary: $family-sans-serif; @import "../bookwyrm.scss"; +@import "../vendor/icons.css"; From f54d4863fe968d0e28b32bb320bacc2fbfb5d5e3 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 09:37:51 -0800 Subject: [PATCH 15/33] Updates .gitignore for themes --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 92fc85bc..ec2a08f8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,8 @@ .env /images/ bookwyrm/static/css/bookwyrm.css -bookwyrm/static/css/_instance-settings.scss +bookwyrm/static/css/themes/ +!bookwyrm/static/css/themes/bookwyrm-*.scss # Testing .coverage From a00ee8a7062df15104fafeb4ce054e011d4e901b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 09:43:31 -0800 Subject: [PATCH 16/33] Adds link to set instance-wide theme --- bookwyrm/templates/settings/themes.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bookwyrm/templates/settings/themes.html b/bookwyrm/templates/settings/themes.html index 11c34405..e3035b2f 100644 --- a/bookwyrm/templates/settings/themes.html +++ b/bookwyrm/templates/settings/themes.html @@ -5,6 +5,12 @@ {% block header %}{% trans "Themes" %}{% endblock %} +{% block breadcrumbs %} + + {% trans "Set instance default theme" %} + +{% endblock %} + {% block panel %} {% if success %}
      From 295d9c42d79c4a33a162fc0ddbc481eb857c9390 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 09:45:34 -0800 Subject: [PATCH 17/33] Adds theme to user settings form --- bookwyrm/forms.py | 1 + bookwyrm/templates/preferences/edit_user.html | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 01228b8e..0baaaa21 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -155,6 +155,7 @@ class EditUserForm(CustomForm): "discoverable", "preferred_timezone", "preferred_language", + "theme", ] help_texts = {f: None for f in fields} widgets = { diff --git a/bookwyrm/templates/preferences/edit_user.html b/bookwyrm/templates/preferences/edit_user.html index 642d177c..e55311ae 100644 --- a/bookwyrm/templates/preferences/edit_user.html +++ b/bookwyrm/templates/preferences/edit_user.html @@ -97,6 +97,12 @@ {{ form.preferred_language }}
      +
      + +
      + {{ form.theme }} +
      +
      From 106ef2e3a49139ec8575529c0644caca7918cce1 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 09:46:05 -0800 Subject: [PATCH 18/33] Fixes reference to theme in layout --- bookwyrm/templates/layout.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index aaf21717..444241e5 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -9,7 +9,7 @@ {% block title %}BookWyrm{% endblock %} - {{ site.name }} {% with theme_path=user.get_theme %} - + {% endwith %} From c82042f5060ff5976d0814ae3c2ae15584fabd06 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 09:54:07 -0800 Subject: [PATCH 19/33] Delete themes --- bookwyrm/templates/settings/themes.html | 8 ++++++-- bookwyrm/urls.py | 5 +++++ bookwyrm/views/__init__.py | 2 +- bookwyrm/views/admin/themes.py | 11 +++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/settings/themes.html b/bookwyrm/templates/settings/themes.html index e3035b2f..d3dac804 100644 --- a/bookwyrm/templates/settings/themes.html +++ b/bookwyrm/templates/settings/themes.html @@ -123,8 +123,12 @@ {{ theme.name }} {{ theme.path }} -
      - + + {% csrf_token %} +
      diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index bef6786d..415af912 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -87,6 +87,11 @@ urlpatterns = [ ), re_path(r"^settings/site-settings/?$", views.Site.as_view(), name="settings-site"), re_path(r"^settings/themes/?$", views.Themes.as_view(), name="settings-themes"), + re_path( + r"^settings/themes/(?P\d+)/delete/?$", + views.delete_theme, + name="settings-themes-delete", + ), re_path( r"^settings/announcements/?$", views.Announcements.as_view(), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 675221cb..957a0f6e 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -21,7 +21,7 @@ from .admin.reports import ( moderator_delete_user, ) from .admin.site import Site -from .admin.themes import Themes +from .admin.themes import Themes, delete_theme from .admin.user_admin import UserAdmin, UserAdminList # user preferences diff --git a/bookwyrm/views/admin/themes.py b/bookwyrm/views/admin/themes.py index c1eacf44..12b449af 100644 --- a/bookwyrm/views/admin/themes.py +++ b/bookwyrm/views/admin/themes.py @@ -2,9 +2,11 @@ from django.contrib.auth.decorators import login_required, permission_required from django.contrib.staticfiles.utils import get_files from django.contrib.staticfiles.storage import StaticFilesStorage +from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View +from django.views.decorators.http import require_POST from bookwyrm import forms, models @@ -46,3 +48,12 @@ def get_view_data(): "choices": [c for c in choices if c not in current and c[-5:] == ".scss"], "theme_form": forms.ThemeForm(), } + + +@require_POST +@permission_required("bookwyrm.edit_instance_settings", raise_exception=True) +# pylint: disable=unused-argument +def delete_theme(request, theme_id): + """Remove a theme""" + get_object_or_404(models.Theme, id=theme_id).delete() + return redirect("settings-themes") From a6883b5b8765498e0918984e9b503c5f35430b21 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 28 Feb 2022 13:30:02 -0800 Subject: [PATCH 20/33] Adds merge migration --- ...142_auto_20220227_1752_0142_user_hide_follows.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bookwyrm/migrations/0143_merge_0142_auto_20220227_1752_0142_user_hide_follows.py diff --git a/bookwyrm/migrations/0143_merge_0142_auto_20220227_1752_0142_user_hide_follows.py b/bookwyrm/migrations/0143_merge_0142_auto_20220227_1752_0142_user_hide_follows.py new file mode 100644 index 00000000..b36fa9f9 --- /dev/null +++ b/bookwyrm/migrations/0143_merge_0142_auto_20220227_1752_0142_user_hide_follows.py @@ -0,0 +1,13 @@ +# Generated by Django 3.2.12 on 2022-02-28 21:28 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0142_auto_20220227_1752"), + ("bookwyrm", "0142_user_hide_follows"), + ] + + operations = [] From b4222bead4a039e6c5c0d793d18b11bd314d3cf6 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Mon, 28 Feb 2022 23:01:33 -0800 Subject: [PATCH 21/33] Remove uuid for status reply panel - The focus target did not include this uuid, so was throwing `Uncaught TypeError: node is null` when clicking on Reply button. - I wasn't able to figure out how to share the uuid between blocks but it doesn't seem like the uuid is really needed -- the same block has other ids that do not have the uuid in them. --- bookwyrm/templates/snippets/status/layout.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/bookwyrm/templates/snippets/status/layout.html b/bookwyrm/templates/snippets/status/layout.html index a7727042..4e5b75cc 100644 --- a/bookwyrm/templates/snippets/status/layout.html +++ b/bookwyrm/templates/snippets/status/layout.html @@ -69,7 +69,6 @@ {% block card-bonus %} {% if request.user.is_authenticated and not moderation_mode and not no_interact %} -{% with status.id|uuid as uuid %} -{% endwith %} {% endif %} {% endblock %} From 8e9bacc527f7d5e906c1b30bb071e0a9d68d6eb2 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Mon, 28 Feb 2022 23:31:57 -0800 Subject: [PATCH 22/33] Fix red for being too harsh --- bookwyrm/static/css/themes/bookwyrm-dark.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/static/css/themes/bookwyrm-dark.scss b/bookwyrm/static/css/themes/bookwyrm-dark.scss index 216fa1e8..e363572d 100644 --- a/bookwyrm/static/css/themes/bookwyrm-dark.scss +++ b/bookwyrm/static/css/themes/bookwyrm-dark.scss @@ -13,6 +13,7 @@ $warning: #8b6c15; $danger: #872538; $danger-light: #481922; $light: #393939; +$red: #ffa1b4; /* book cover standins */ $no-cover-color: #002549; From f4dc07b6b90909ab28cda3ec5e37d3f471801a34 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 1 Mar 2022 09:49:34 -0800 Subject: [PATCH 23/33] Select theme in context processors --- bookwyrm/context_processors.py | 10 ++- bookwyrm/models/user.py | 11 --- bookwyrm/templates/layout.html | 4 +- bookwyrm/tests/test_context_processors.py | 86 +++++++++++++++++++++++ 4 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 bookwyrm/tests/test_context_processors.py diff --git a/bookwyrm/context_processors.py b/bookwyrm/context_processors.py index 309e84ed..b5110d24 100644 --- a/bookwyrm/context_processors.py +++ b/bookwyrm/context_processors.py @@ -8,8 +8,16 @@ def site_settings(request): # pylint: disable=unused-argument if not request.is_secure(): request_protocol = "http://" + site = models.SiteSettings.objects.get() + theme = "css/themes/bookwyrm-light.scss" + if request.user.is_authenticated and request.user.theme: + theme = request.user.theme.path + elif site.default_theme: + theme = site.default_theme.path + return { - "site": models.SiteSettings.objects.get(), + "site": site, + "site_theme": theme, "active_announcements": models.Announcement.active_announcements(), "thumbnail_generation_enabled": settings.ENABLE_THUMBNAIL_GENERATION, "media_full_url": settings.MEDIA_FULL_URL, diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index e4b98db3..be5c1992 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -174,17 +174,6 @@ class User(OrderedCollectionPageMixin, AbstractUser): property_fields = [("following_link", "following")] field_tracker = FieldTracker(fields=["name", "avatar"]) - @property - def get_theme(self): - """get the theme given the user/site""" - if self.theme: - return self.theme.path - site_model = apps.get_model("bookwyrm", "SiteSettings", require_ready=True) - site = site_model.objects.get() - if site.default_theme: - return site.default_theme.path - return "css/themes/bookwyrm-light.scss" - @property def confirmation_link(self): """helper for generating confirmation links""" diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 444241e5..51ba7915 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -8,9 +8,7 @@ {% block title %}BookWyrm{% endblock %} - {{ site.name }} - {% with theme_path=user.get_theme %} - - {% endwith %} + diff --git a/bookwyrm/tests/test_context_processors.py b/bookwyrm/tests/test_context_processors.py new file mode 100644 index 00000000..3d634aaf --- /dev/null +++ b/bookwyrm/tests/test_context_processors.py @@ -0,0 +1,86 @@ +""" test for context processor """ +from unittest.mock import patch +from django.contrib.auth.models import AnonymousUser +from django.test import TestCase +from django.test.client import RequestFactory + +from bookwyrm import models +from bookwyrm.context_processors import site_settings + + +class ContextProcessor(TestCase): + """pages you land on without really trying""" + + def setUp(self): + """we need basic test data and mocks""" + self.factory = RequestFactory() + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False + self.site = models.SiteSettings.objects.create() + + def test_theme_unset(self): + """logged in user, no selected theme""" + request = self.factory.get("") + request.user = self.local_user + settings = site_settings(request) + self.assertEqual(settings["site_theme"], "css/themes/bookwyrm-light.scss") + + def test_theme_unset_logged_out(self): + """logged out user, no selected theme""" + request = self.factory.get("") + request.user = self.anonymous_user + settings = site_settings(request) + self.assertEqual(settings["site_theme"], "css/themes/bookwyrm-light.scss") + + def test_theme_instance_default(self): + """logged in user, instance default theme""" + self.site.default_theme = models.Theme.objects.get(name="BookWyrm Dark") + self.site.save() + + request = self.factory.get("") + request.user = self.local_user + settings = site_settings(request) + self.assertEqual(settings["site_theme"], "css/themes/bookwyrm-dark.scss") + + def test_theme_instance_default_logged_out(self): + """logged out user, instance default theme""" + self.site.default_theme = models.Theme.objects.get(name="BookWyrm Dark") + self.site.save() + + request = self.factory.get("") + request.user = self.anonymous_user + settings = site_settings(request) + self.assertEqual(settings["site_theme"], "css/themes/bookwyrm-dark.scss") + + def test_theme_user_set(self): + """logged in user, user theme""" + self.local_user.theme = models.Theme.objects.get(name="BookWyrm Dark") + self.local_user.save(broadcast=False, update_fields=["theme"]) + + request = self.factory.get("") + request.user = self.local_user + settings = site_settings(request) + self.assertEqual(settings["site_theme"], "css/themes/bookwyrm-dark.scss") + + def test_theme_user_set_instance_default(self): + """logged in user, instance default theme""" + self.site.default_theme = models.Theme.objects.get(name="BookWyrm Dark") + self.site.save() + + self.local_user.theme = models.Theme.objects.get(name="BookWyrm Light") + self.local_user.save(broadcast=False, update_fields=["theme"]) + + request = self.factory.get("") + request.user = self.local_user + settings = site_settings(request) + self.assertEqual(settings["site_theme"], "css/themes/bookwyrm-light.scss") From d1d743281a5ccf25ce0d903fb2eae01ba2b3231c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 1 Mar 2022 10:28:51 -0800 Subject: [PATCH 24/33] Cleans up display of superlatives on about page --- bookwyrm/templates/about/about.html | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bookwyrm/templates/about/about.html b/bookwyrm/templates/about/about.html index 553bfee1..f1ddd2f3 100644 --- a/bookwyrm/templates/about/about.html +++ b/bookwyrm/templates/about/about.html @@ -14,23 +14,25 @@ {% cache 604800 about_page %} {% get_book_superlatives as superlatives %} -
      -

      - {% blocktrans with site_name=site.name %}Welcome to {{ site_name }}!{% endblocktrans %} -

      +
      +
      +

      + {% blocktrans with site_name=site.name %}Welcome to {{ site_name }}!{% endblocktrans %} +

      -

      - {% blocktrans trimmed with site_name=site.name %} - {{ site_name }} is part of BookWyrm, a network of independent, self-directed communities for readers. - While you can interact seamlessly with users anywhere in the BookWyrm network, this community is unique. - {% endblocktrans %} -

      +

      + {% blocktrans trimmed with site_name=site.name %} + {{ site_name }} is part of BookWyrm, a network of independent, self-directed communities for readers. + While you can interact seamlessly with users anywhere in the BookWyrm network, this community is unique. + {% endblocktrans %} +

      +
      {% if superlatives.top_rated %} {% with book=superlatives.top_rated.default_edition rating=superlatives.top_rated.rating %}
      -
      +
      {% include 'snippets/book_cover.html' with book=book cover_class='is-h-m' size='medium' aria='show' %} @@ -49,7 +51,7 @@ {% if superlatives.wanted %} {% with book=superlatives.wanted.default_edition %}
      -
      +
      {% include 'snippets/book_cover.html' with book=book cover_class='is-h-m' size='medium' aria='show' %} @@ -68,7 +70,7 @@ {% if superlatives.controversial %} {% with book=superlatives.controversial.default_edition %}
      -
      +
      {% include 'snippets/book_cover.html' with book=book cover_class='is-h-m' size='medium' aria='show' %} From 5d7e6b872a9cc576b03fbd42b6d6ebc6775e5963 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 1 Mar 2022 10:34:17 -0800 Subject: [PATCH 25/33] Fixes localizing query for superlatives --- bookwyrm/templatetags/landing_page_tags.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templatetags/landing_page_tags.py b/bookwyrm/templatetags/landing_page_tags.py index e7d94360..ea2512cc 100644 --- a/bookwyrm/templatetags/landing_page_tags.py +++ b/bookwyrm/templatetags/landing_page_tags.py @@ -16,11 +16,15 @@ def get_book_superlatives(): models.Work.objects.annotate( rating=Avg( "editions__review__rating", - filter=Q(editions__review__local=True, editions__review__deleted=False), + filter=Q( + editions__review__user__local=True, editions__review__deleted=False + ), ), rating_count=Count( "editions__review", - filter=Q(editions__review__local=True, editions__review__deleted=False), + filter=Q( + editions__review__user__local=True, editions__review__deleted=False + ), ), ) .annotate(weighted=F("rating") * F("rating_count") / total_ratings) @@ -33,11 +37,15 @@ def get_book_superlatives(): models.Work.objects.annotate( deviation=StdDev( "editions__review__rating", - filter=Q(editions__review__local=True, editions__review__deleted=False), + filter=Q( + editions__review__user__local=True, editions__review__deleted=False + ), ), rating_count=Count( "editions__review", - filter=Q(editions__review__local=True, editions__review__deleted=False), + filter=Q( + editions__review__user__local=True, editions__review__deleted=False + ), ), ) .annotate(weighted=F("deviation") * F("rating_count") / total_ratings) From 9422a07414262df83fe3eeecf23db530aba179ea Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 1 Mar 2022 10:36:19 -0800 Subject: [PATCH 26/33] Safer query for request user for tests --- bookwyrm/context_processors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/context_processors.py b/bookwyrm/context_processors.py index b5110d24..aeab55e2 100644 --- a/bookwyrm/context_processors.py +++ b/bookwyrm/context_processors.py @@ -10,7 +10,7 @@ def site_settings(request): # pylint: disable=unused-argument site = models.SiteSettings.objects.get() theme = "css/themes/bookwyrm-light.scss" - if request.user.is_authenticated and request.user.theme: + if request.user and request.user.is_authenticated and request.user.theme: theme = request.user.theme.path elif site.default_theme: theme = site.default_theme.path From 55f1ce12cfb92c8e0df819ae6c145db4fbaf3438 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 1 Mar 2022 11:05:47 -0800 Subject: [PATCH 27/33] Second attempt at fixing tests using context processors --- bookwyrm/context_processors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/context_processors.py b/bookwyrm/context_processors.py index aeab55e2..9de75eda 100644 --- a/bookwyrm/context_processors.py +++ b/bookwyrm/context_processors.py @@ -10,7 +10,7 @@ def site_settings(request): # pylint: disable=unused-argument site = models.SiteSettings.objects.get() theme = "css/themes/bookwyrm-light.scss" - if request.user and request.user.is_authenticated and request.user.theme: + if hasattr(request, "user") and request.user.is_authenticated and request.user.theme: theme = request.user.theme.path elif site.default_theme: theme = site.default_theme.path From 41ea7db8b612dc01b3ada5d87a90b4242890030d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 1 Mar 2022 11:06:15 -0800 Subject: [PATCH 28/33] Removes hardcoded white in announcements --- .../0144_alter_announcement_display_type.py | 39 +++++++++++++++++++ bookwyrm/models/announcement.py | 7 +--- bookwyrm/templates/snippets/announcement.html | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 bookwyrm/migrations/0144_alter_announcement_display_type.py diff --git a/bookwyrm/migrations/0144_alter_announcement_display_type.py b/bookwyrm/migrations/0144_alter_announcement_display_type.py new file mode 100644 index 00000000..246dd5b4 --- /dev/null +++ b/bookwyrm/migrations/0144_alter_announcement_display_type.py @@ -0,0 +1,39 @@ +# Generated by Django 3.2.12 on 2022-03-01 18:46 + +from django.db import migrations, models + + +def remove_white(apps, schema_editor): + """don't hardcode white announcements""" + db_alias = schema_editor.connection.alias + announcement_model = apps.get_model("bookwyrm", "Announcement") + announcement_model.objects.using(db_alias).filter(display_type="white-ter").update( + display_type=None + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0143_merge_0142_auto_20220227_1752_0142_user_hide_follows"), + ] + + operations = [ + migrations.AlterField( + model_name="announcement", + name="display_type", + field=models.CharField( + blank=True, + choices=[ + ("primary-light", "Primary"), + ("success-light", "Success"), + ("link-light", "Link"), + ("warning-light", "Warning"), + ("danger-light", "Danger"), + ], + max_length=20, + null=True, + ), + ), + migrations.RunPython(remove_white, reverse_code=migrations.RunPython.noop), + ] diff --git a/bookwyrm/models/announcement.py b/bookwyrm/models/announcement.py index cbed38ae..4581dbda 100644 --- a/bookwyrm/models/announcement.py +++ b/bookwyrm/models/announcement.py @@ -8,7 +8,6 @@ from .base_model import BookWyrmModel DisplayTypes = [ - ("white-ter", _("None")), ("primary-light", _("Primary")), ("success-light", _("Success")), ("link-light", _("Link")), @@ -28,11 +27,7 @@ class Announcement(BookWyrmModel): end_date = models.DateTimeField(blank=True, null=True) active = models.BooleanField(default=True) display_type = models.CharField( - max_length=20, - blank=False, - null=False, - choices=DisplayTypes, - default="white-ter", + max_length=20, choices=DisplayTypes, null=True, blank=True ) @classmethod diff --git a/bookwyrm/templates/snippets/announcement.html b/bookwyrm/templates/snippets/announcement.html index ec1555d8..d9da01c9 100644 --- a/bookwyrm/templates/snippets/announcement.html +++ b/bookwyrm/templates/snippets/announcement.html @@ -1,7 +1,7 @@ {% load humanize %}{% load i18n %}{% load utilities %} {% with announcement.id|uuid as uuid %}