Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

import json 

 

from asgiref.sync import async_to_sync 

from channels.layers import get_channel_layer 

from django.db.models.signals import post_save 

 

from notifier.models import Notification 

 

channel_layer = get_channel_layer() 

 

 

def send_new_notification_to_user(sender, instance, created, **kwargs): 

if created is True and instance.in_top_bar is True: 

target_user = instance.target 

 

# send notification to user group 

group_name = "notifier_" + str(target_user.id) 

text = {"action": "new_notification", 

"link": instance.link, 

"read": instance.read, 

"notificationid": instance.id, 

"reverse": instance.reverse, 

"subject": str(instance.subject), 

"verb": instance.verb, 

"target": str(target_user), 

"image": instance.get_representative_image(), 

"date": instance.get_date()} 

 

async_to_sync(channel_layer.group_send)( 

group_name, { 

"type": "message.new", 

"text": json.dumps(text) 

} 

) 

 

 

post_save.connect(send_new_notification_to_user, 

sender=Notification)