Merge branch 'aureplop/clean_channels' into 'master'

Aureplop/clean channels

Closes #67

See merge request !220
This commit is contained in:
Martin Pepin 2017-04-11 00:42:08 +02:00
commit a725f8020c
2 changed files with 34 additions and 19 deletions

View file

@ -1,26 +1,41 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, from django.core.serializers.json import json, DjangoJSONEncoder
print_function, unicode_literals)
from builtins import *
from channels import Group
from channels.generic.websockets import JsonWebsocketConsumer from channels.generic.websockets import JsonWebsocketConsumer
class KPsul(JsonWebsocketConsumer):
# Set to True if you want them, else leave out class DjangoJsonWebsocketConsumer(JsonWebsocketConsumer):
strict_ordering = False """Custom Json Websocket Consumer.
slight_ordering = False
def connection_groups(self, **kwargs): Encode to JSON with DjangoJSONEncoder.
return ['kfet.kpsul']
"""
@classmethod
def encode_json(cls, content):
return json.dumps(content, cls=DjangoJSONEncoder)
class PermConsumerMixin(object):
"""Add support to check permissions on Consumers.
Attributes:
perms_connect (list): Required permissions to connect to this
consumer.
"""
http_user = True # Enable message.user
perms_connect = []
def connect(self, message, **kwargs): def connect(self, message, **kwargs):
pass """Check permissions on connection."""
if message.user.has_perms(self.perms_connect):
super().connect(message, **kwargs)
else:
self.close()
def receive(self, content, **kwargs):
pass
def disconnect(self, message, **kwargs): class KPsul(PermConsumerMixin, DjangoJsonWebsocketConsumer):
pass groups = ['kfet.kpsul']
perms_connect = ['kfet.is_team']

View file

@ -12,13 +12,13 @@ six==1.10.0
unicodecsv==0.14.1 unicodecsv==0.14.1
icalendar==3.10 icalendar==3.10
django-bootstrap-form==3.2.1 django-bootstrap-form==3.2.1
asgiref==0.14.0 asgiref==1.1.1
daphne==0.14.3 daphne==1.2.0
asgi-redis==0.14.0 asgi-redis==1.3.0
statistics==1.0.3.5 statistics==1.0.3.5
future==0.15.2 future==0.15.2
django-widget-tweaks==1.4.1 django-widget-tweaks==1.4.1
git+https://git.eleves.ens.fr/cof-geek/django_custommail.git#egg=django_custommail git+https://git.eleves.ens.fr/cof-geek/django_custommail.git#egg=django_custommail
ldap3 ldap3
git+https://github.com/Aureplop/channels.git#egg=channels channels==1.1.3
python-dateutil python-dateutil