Guest User

Untitled

a guest
Oct 11th, 2020
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. consumers.py
  2. class NotificationConsumer(WebsocketConsumer):
  3. def connect(self):
  4. if self.scope["user"].is_anonymous:
  5. self.close()
  6. else:
  7. self.group_name = "user_id_" + str(self.scope["user"].id)
  8. async_to_sync(self.channel_layer.group_add)(
  9. self.group_name, self.channel_name
  10. )
  11. self.accept()
  12.  
  13. def disconnect(self, close_code):
  14. self.close()
  15.  
  16. def notify(self, event):
  17. self.send(text_data=json.dumps(event["text"]))
  18.  
Advertisement
Add Comment
Please, Sign In to add comment