Add digest settings (despite not being implemented)

This commit is contained in:
rubenwardy 2020-12-05 21:59:02 +00:00
parent 4019e82f4a
commit a17260a4ee
3 changed files with 36 additions and 11 deletions

@ -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

@ -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):

@ -26,21 +26,32 @@
{% if is_new %}
<p class="alert alert-info">
{{ _("Email notifications are currently turned off. Click 'Save' to apply recommended settings.") }}
{{ _("Email notifications are currently turned off. Click 'save' to enable.") }}
</p>
{% endif %}
<p>
Configure whether certain types of notifications are sent immediately, or as part of a daily digest. <br>
<i>Note: daily digests aren't implemented yet.</i>
</p>
<table class="table">
<tr>
<th>Event</th>
<th>Description</th>
<td>Emails?</td>
<td>Immediately</td>
<td>In digest</td>
</tr>
{% for type in types %}
<tr>
<td>{{ type.getTitle() }}</td>
<td>{{ type.get_description() }}</td>
<td>{{ render_checkbox_field(form["pref_" + type.toName()]) }}</td>
<td style="text-align: center;">
{{ render_checkbox_field(form["pref_" + type.toName()]) }}
</td>
<td style="text-align: center;">
{{ render_checkbox_field(form["pref_" + type.toName() + "_digest"]) }}
</td>
</tr>
{% endfor %}
</table>