Merge branch 'master' into aureplop/kfet_open

This commit is contained in:
Aurélien Delobelle 2017-06-12 15:18:42 +02:00
commit ec59bc2edc
100 changed files with 3401 additions and 2508 deletions

View file

@ -1,29 +1,40 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django.core.serializers.json import json, DjangoJSONEncoder
from channels import Group
from channels.generic.websockets import JsonWebsocketConsumer
class KPsul(JsonWebsocketConsumer):
# Set to True if you want them, else leave out
strict_ordering = False
slight_ordering = False
class DjangoJsonWebsocketConsumer(JsonWebsocketConsumer):
"""Custom Json Websocket Consumer.
def connection_groups(self, **kwargs):
return ['kfet.kpsul']
Encode to JSON with DjangoJSONEncoder.
"""
@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):
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):
pass
class KfetOpen(JsonWebsocketConsumer):
def connection_groups(self, **kwargs):
@ -37,3 +48,8 @@ class KfetOpen(JsonWebsocketConsumer):
def disconnect(self, message, **kwargs):
pass
class KPsul(PermConsumerMixin, DjangoJsonWebsocketConsumer):
groups = ['kfet.kpsul']
perms_connect = ['kfet.is_team']