Skip to content

Commit

Permalink
Notifications: change wording and use notification instead of categor…
Browse files Browse the repository at this point in the history
…y to indicate a notification instance/class.
  • Loading branch information
thet committed Oct 30, 2023
1 parent 85d5ebe commit 664c110
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
31 changes: 15 additions & 16 deletions src/euphorie/client/browser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def getContent(self):
return user

@property
def notification_categories(self):
categories = getAdapters((self.context, self.request), INotificationCategory)
for category in categories:
if not category[1].available:
def all_notifications(self):
notifications = getAdapters((self.context, self.request), INotificationCategory)
for notification in notifications:
if not notification[1].available:
continue
yield category[1]
yield notification[1]

@property
@memoize
Expand All @@ -169,9 +169,9 @@ def existing_notification_subscriptions(self):
return {subscription.category: subscription for subscription in subscriptions}

def subscribe_notification(self, category_id):
category = self.existing_notification_subscriptions.get(category_id)
if category:
category.enabled = True
notification = self.existing_notification_subscriptions.get(category_id)
if notification:
notification.enabled = True
return
Session.add(
NotificationSubscription(
Expand All @@ -182,9 +182,9 @@ def subscribe_notification(self, category_id):
)

def unsubscribe_notification(self, category_id):
category = self.existing_notification_subscriptions.get(category_id)
if category:
category.enabled = False
notification = self.existing_notification_subscriptions.get(category_id)
if notification:
notification.enabled = False
return
Session.add(
NotificationSubscription(
Expand All @@ -207,12 +207,11 @@ def handleSave(self, action):
user.last_name = data["last_name"]

if self.show_notifications:
notifications = self.request.get("notifications", {})
for category in self.notification_categories:
if notifications.get(category.id):
self.subscribe_notification(category.id)
for notification in self.all_notifications:
if self.request.get("notifications", {}).get(notification.id):
self.subscribe_notification(notification.id)
else:
self.unsubscribe_notification(category.id)
self.unsubscribe_notification(notification.id)


class AccountSettings(AutoExtensibleForm, form.Form):
Expand Down
14 changes: 7 additions & 7 deletions src/euphorie/client/browser/templates/preferences.pt
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@
<fieldset class="form-panel pat-collapsible true section horizontal"
id="label-notifications"
data-pat-collapsible="store: local; scroll-selector: self; scroll-offset: 100px"
tal:define="categories view/notification_categories"
tal:condition="python: view.show_notifications and categories"
tal:define="notifications view/all_notifications"
tal:condition="python: view.show_notifications and notifications"
>

<h3 class="form-separation-header"
i18n:translate="label_mailings"
>Notifications
</h3>
<fieldset class="pat-checklist group checkbox">
<tal:loop repeat="category categories">
<tal:loop repeat="notification notifications">
<label class="">
<input checked="${python:'checked' if getattr(view.existing_notification_subscriptions.get(category.id, None), 'enabled', category.default) else None}"
name="notifications.${category/id}:boolean:record"
<input checked="${python:'checked' if getattr(view.existing_notification_subscriptions.get(notification.id, None), 'enabled', notification.default) else None}"
name="notifications.${notification/id}:boolean:record"
type="checkbox"
value="true"
/>
<strong class="label-fragment-title">${category/title}</strong>
<p class="label-fragment-description">${category/description}</p>
<strong class="label-fragment-title">${notification/title}</strong>
<p class="label-fragment-description">${notification/description}</p>
</label>
<br />
</tal:loop>
Expand Down

0 comments on commit 664c110

Please sign in to comment.