Add digest settings (despite not being implemented)
This commit is contained in:
parent
4019e82f4a
commit
a17260a4ee
|
@ -101,16 +101,19 @@ def make_settings_form():
|
||||||
for notificationType in NotificationType:
|
for notificationType in NotificationType:
|
||||||
key = "pref_" + notificationType.toName()
|
key = "pref_" + notificationType.toName()
|
||||||
attrs[key] = BooleanField("")
|
attrs[key] = BooleanField("")
|
||||||
|
attrs[key + "_digest"] = BooleanField("")
|
||||||
|
|
||||||
return type("SettingsForm", (FlaskForm,), attrs)
|
return type("SettingsForm", (FlaskForm,), attrs)
|
||||||
|
|
||||||
SettingsForm = make_settings_form()
|
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:
|
for notificationType in NotificationType:
|
||||||
field = getattr(form, "pref_" + notificationType.toName())
|
field_email = getattr(form, "pref_" + notificationType.toName()).data
|
||||||
prefs.set_can_email(notificationType, field.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:
|
if is_new:
|
||||||
db.session.add(prefs)
|
db.session.add(prefs)
|
||||||
|
@ -167,6 +170,7 @@ def email_notifications(username=None):
|
||||||
for notificationType in NotificationType:
|
for notificationType in NotificationType:
|
||||||
types.append(notificationType)
|
types.append(notificationType)
|
||||||
data["pref_" + notificationType.toName()] = prefs.get_can_email(notificationType)
|
data["pref_" + notificationType.toName()] = prefs.get_can_email(notificationType)
|
||||||
|
data["pref_" + notificationType.toName() + "_digest"] = prefs.get_can_digest(notificationType)
|
||||||
|
|
||||||
data["email"] = user.email
|
data["email"] = user.email
|
||||||
|
|
||||||
|
|
|
@ -421,19 +421,29 @@ class UserNotificationPreferences(db.Model):
|
||||||
self.pref_package_edit = 1
|
self.pref_package_edit = 1
|
||||||
self.pref_package_approval = 2
|
self.pref_package_approval = 2
|
||||||
self.pref_new_thread = 2
|
self.pref_new_thread = 2
|
||||||
self.pref_new_review = 2
|
self.pref_new_review = 1
|
||||||
self.pref_thread_reply = 2
|
self.pref_thread_reply = 2
|
||||||
self.pref_maintainer = 2
|
self.pref_maintainer = 2
|
||||||
self.pref_editor_alert = 2
|
self.pref_editor_alert = 2
|
||||||
self.pref_editor_misc = 0
|
self.pref_editor_misc = 0
|
||||||
self.pref_other = 0
|
self.pref_other = 0
|
||||||
|
|
||||||
def get_can_email(self, type):
|
def get_can_email(self, notification_type):
|
||||||
return getattr(self, "pref_" + type.toName()) == 2
|
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
|
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):
|
class License(db.Model):
|
||||||
|
|
|
@ -26,21 +26,32 @@
|
||||||
|
|
||||||
{% if is_new %}
|
{% if is_new %}
|
||||||
<p class="alert alert-info">
|
<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>
|
</p>
|
||||||
{% endif %}
|
{% 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">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Event</th>
|
<th>Event</th>
|
||||||
<th>Description</th>
|
<th>Description</th>
|
||||||
<td>Emails?</td>
|
<td>Immediately</td>
|
||||||
|
<td>In digest</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for type in types %}
|
{% for type in types %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ type.getTitle() }}</td>
|
<td>{{ type.getTitle() }}</td>
|
||||||
<td>{{ type.get_description() }}</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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue