From a17260a4eeae617103987a90318a8f578b7eed7d Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 5 Dec 2020 21:59:02 +0000 Subject: [PATCH] Add digest settings (despite not being implemented) --- app/blueprints/users/settings.py | 10 +++++++--- app/models.py | 20 +++++++++++++++----- app/templates/users/settings_email.html | 17 ++++++++++++++--- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/app/blueprints/users/settings.py b/app/blueprints/users/settings.py index b4d7153..36ac03a 100644 --- a/app/blueprints/users/settings.py +++ b/app/blueprints/users/settings.py @@ -101,16 +101,19 @@ def make_settings_form(): for notificationType in NotificationType: key = "pref_" + notificationType.toName() attrs[key] = BooleanField("") + attrs[key + "_digest"] = BooleanField("") return type("SettingsForm", (FlaskForm,), attrs) SettingsForm = make_settings_form() -def handle_email_notifications(user, prefs, is_new, form): +def handle_email_notifications(user, prefs: UserNotificationPreferences, is_new, form): for notificationType in NotificationType: - field = getattr(form, "pref_" + notificationType.toName()) - prefs.set_can_email(notificationType, field.data) + field_email = getattr(form, "pref_" + notificationType.toName()).data + field_digest = getattr(form, "pref_" + notificationType.toName() + "_digest").data or field_email + prefs.set_can_email(notificationType, field_email) + prefs.set_can_digest(notificationType, field_digest) if is_new: db.session.add(prefs) @@ -167,6 +170,7 @@ def email_notifications(username=None): for notificationType in NotificationType: types.append(notificationType) data["pref_" + notificationType.toName()] = prefs.get_can_email(notificationType) + data["pref_" + notificationType.toName() + "_digest"] = prefs.get_can_digest(notificationType) data["email"] = user.email diff --git a/app/models.py b/app/models.py index 2cdcb74..7673d4e 100644 --- a/app/models.py +++ b/app/models.py @@ -421,19 +421,29 @@ class UserNotificationPreferences(db.Model): self.pref_package_edit = 1 self.pref_package_approval = 2 self.pref_new_thread = 2 - self.pref_new_review = 2 + self.pref_new_review = 1 self.pref_thread_reply = 2 self.pref_maintainer = 2 self.pref_editor_alert = 2 self.pref_editor_misc = 0 self.pref_other = 0 - def get_can_email(self, type): - return getattr(self, "pref_" + type.toName()) == 2 + def get_can_email(self, notification_type): + return getattr(self, "pref_" + notification_type.toName()) == 2 - def set_can_email(self, type, value): + def set_can_email(self, notification_type, value): value = 2 if value else 0 - setattr(self, "pref_" + type.toName(), value) + setattr(self, "pref_" + notification_type.toName(), value) + + def get_can_digest(self, notification_type): + return getattr(self, "pref_" + notification_type.toName()) >= 1 + + def set_can_digest(self, notification_type, value): + if self.get_can_email(notification_type): + return + + value = 1 if value else 0 + setattr(self, "pref_" + notification_type.toName(), value) class License(db.Model): diff --git a/app/templates/users/settings_email.html b/app/templates/users/settings_email.html index 5203975..601aa49 100644 --- a/app/templates/users/settings_email.html +++ b/app/templates/users/settings_email.html @@ -26,21 +26,32 @@ {% if is_new %}

- {{ _("Email notifications are currently turned off. Click 'Save' to apply recommended settings.") }} + {{ _("Email notifications are currently turned off. Click 'save' to enable.") }}

{% endif %} +

+ Configure whether certain types of notifications are sent immediately, or as part of a daily digest.
+ Note: daily digests aren't implemented yet. +

+ - + + {% for type in types %} - + + {% endfor %}
Event DescriptionEmails?ImmediatelyIn digest
{{ type.getTitle() }} {{ type.get_description() }}{{ render_checkbox_field(form["pref_" + type.toName()]) }} + {{ render_checkbox_field(form["pref_" + type.toName()]) }} + + {{ render_checkbox_field(form["pref_" + type.toName() + "_digest"]) }} +