Widening the use case for the notifications. · pythonDrive/bootcamp@2c267b7 · GitHub
Skip to content

Commit 2c267b7

Browse files
Widening the use case for the notifications.
1 parent 6d376a2 commit 2c267b7

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

bootcamp/notifications/consumers.py

Lines changed: 7 additions & 5 deletions

bootcamp/notifications/models.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ def notification_handler(actor, recipient, verb, **kwargs):
210210
:param verb: Notification attribute with the right choice from the list.
211211
212212
:optional:
213-
:action_object: Model instance on which the verb was executed.
213+
:param action_object: Model instance on which the verb was executed.
214+
:param key: String defining what kind of notification is going to be created.
215+
:param id_value: UUID value assigned to a specific element in the DOM.
214216
"""
215217
key = kwargs.pop('key', 'notification')
216218
id_value = kwargs.pop('id_value', None)
@@ -224,6 +226,8 @@ def notification_handler(actor, recipient, verb, **kwargs):
224226
action_object=kwargs.pop('action_object', None)
225227
)
226228

229+
notification_broadcast(actor, key)
230+
227231
elif isinstance(recipient, list):
228232
for user in recipient:
229233
Notification.objects.create(
@@ -240,13 +244,20 @@ def notification_handler(actor, recipient, verb, **kwargs):
240244
verb=verb,
241245
action_object=kwargs.pop('action_object', None)
242246
)
247+
notification_broadcast(
248+
actor, key, id_value=id_value, recipient=recipient)
243249

244250
else:
245251
pass
246-
notification_broadcast(actor, key, id_value)
247252

248253

249-
def notification_broadcast(actor, key, id_value):
254+
def notification_broadcast(actor, key, **kwargs):
250255
channel_layer = get_channel_layer()
251-
payload = {'type': 'receive', 'key': key, 'id_value': id_value, 'username': actor.username }
256+
payload = {
257+
'type': 'receive',
258+
'key': key,
259+
'actor_name': actor.username,
260+
'id_value': kwargs.pop('id_value', None),
261+
'recipient': kwargs.pop('recipient', None)
262+
}
252263
async_to_sync(channel_layer.group_send)('notifications', payload)

bootcamp/static/js/bootcamp.js

Lines changed: 3 additions & 2 deletions

0 commit comments

Comments
 (0)