From 41ea7db8b612dc01b3ada5d87a90b4242890030d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 1 Mar 2022 11:06:15 -0800 Subject: [PATCH] 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 000000000..246dd5b4e --- /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 cbed38aee..4581dbdae 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 ec1555d8f..d9da01c96 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 %}