From 2183161916a141f192377897bf4ee2d92effc941 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 20 Dec 2022 03:38:19 +0200 Subject: [PATCH] add toggle for event music --- files/classes/user.py | 8 ++++---- files/routes/settings.py | 4 +++- files/templates/settings/personal.html | 3 +++ migrations/20221220-grinch-toggle.sql | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 migrations/20221220-grinch-toggle.sql diff --git a/files/classes/user.py b/files/classes/user.py index 9c1387e25..98dd4f683 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -138,6 +138,8 @@ class User(Base): marsify = Column(Integer, default=0) rainbow = Column(Integer) spider = Column(Integer, default=0) + if HOLIDAY_EVENT: + event_music = Column(Boolean, default=True, nullable=False) badges = relationship("Badge", order_by="Badge.created_utc", back_populates="user") subscriptions = relationship("Subscription", back_populates="user") @@ -1139,7 +1141,5 @@ class User(Base): if HOLIDAY_EVENT: @property @lazy - def event_music(self): - if SITE_NAME != 'rDrama': return False - if self.has_badge(91): return False - return True + def can_toggle_event_music(self): + return self.has_badge(91) diff --git a/files/routes/settings.py b/files/routes/settings.py index 613c6cea9..9e2f4063f 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -194,7 +194,9 @@ def settings_personal_post(v): else: badge = v.has_badge(179) if badge: g.db.delete(badge) - + elif not updated and request.values.get("event_music", v.event_music) != v.event_music and v.can_toggle_event_music: + updated = True + v.event_music = not v.event_music elif not updated and request.values.get("bio") == "" and not request.files.get('file'): v.bio = None v.bio_html = None diff --git a/files/templates/settings/personal.html b/files/templates/settings/personal.html index 6ba99cf0c..dd16a493d 100644 --- a/files/templates/settings/personal.html +++ b/files/templates/settings/personal.html @@ -19,6 +19,9 @@
Site Experience
+ {% if v.can_toggle_event_music %} + {{common.toggle_section('Event Music', 'event_music_switch', 'event_music', v.event_music, 'Toggle event music.', false)}} + {% endif %}
diff --git a/migrations/20221220-grinch-toggle.sql b/migrations/20221220-grinch-toggle.sql new file mode 100644 index 000000000..3dedd5ed3 --- /dev/null +++ b/migrations/20221220-grinch-toggle.sql @@ -0,0 +1,2 @@ +alter table users add column event_music boolean NOT NULL default True; +alter table users alter column event_music drop default;