-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
204 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
from channels import Group | ||
from channels.sessions import channel_session | ||
from channels.generic.websocket import JsonWebsocketConsumer | ||
|
||
|
||
@channel_session | ||
def ws_connect(message): | ||
""" | ||
Channels connection setup. | ||
Register the current client on the related Group according to the language | ||
""" | ||
prefix, language = message['path'].strip('/').split('/') | ||
gr = Group('knocker-{0}'.format(language)) | ||
gr.add(message.reply_channel) | ||
message.channel_session['knocker'] = language | ||
message.reply_channel.send({"accept": True}) | ||
class KnockerConsumer(JsonWebsocketConsumer): | ||
|
||
@property | ||
def groups(self): | ||
""" | ||
Attach the consumer to the selected language | ||
""" | ||
lang = self.scope['url_route']['kwargs'].get('language') | ||
return 'knocker-%s' % lang, | ||
|
||
@channel_session | ||
def ws_receive(message): | ||
""" | ||
Currently no-op | ||
""" | ||
pass | ||
def knocker_saved(self, event): | ||
""" | ||
This method handles messages sent to knocker.saved | ||
|
||
@channel_session | ||
def ws_disconnect(message): | ||
""" | ||
Channels connection close. | ||
Deregister the client | ||
""" | ||
language = message.channel_session['knocker'] | ||
gr = Group('knocker-{0}'.format(language)) | ||
gr.discard(message.reply_channel) | ||
:param event: event object | ||
""" | ||
self.send_json(content=event['message']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
from . import consumers | ||
from channels.routing import URLRouter | ||
from django.urls import path | ||
|
||
channel_routing = { | ||
'websocket.connect': consumers.ws_connect, | ||
'websocket.receive': consumers.ws_receive, | ||
'websocket.disconnect': consumers.ws_disconnect, | ||
} | ||
from .consumers import KnockerConsumer | ||
|
||
# consumers can be freely appended: path ensure the correct match | ||
channel_routing = URLRouter([ | ||
path('notification/<str:language>/', KnockerConsumer), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
-r requirements-test.txt | ||
Django<2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ flake8>=2.1.0 | |
tox>=1.7.0 | ||
djangocms-helper | ||
django-parler | ||
asgi-redis | ||
pillow | ||
channels-redis | ||
django-sekizai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,4 @@ | |
|
||
from .models import Post | ||
|
||
|
||
admin.site.register(Post) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.