- Use last official releases of channels, asgiref, daphne and asgi-redis packages. - Customization of JsonWebsocketConsumer is now in kfet app through a custom class (and so, doesn't require anymore a forked version of channels). - Clean kfet consumers code.
22 lines
488 B
Python
22 lines
488 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
from django.core.serializers.json import json, DjangoJSONEncoder
|
|
|
|
from channels.generic.websockets import JsonWebsocketConsumer
|
|
|
|
|
|
class DjangoJsonWebsocketConsumer(JsonWebsocketConsumer):
|
|
"""Custom Json Websocket Consumer.
|
|
|
|
Encode to JSON with DjangoJSONEncoder.
|
|
|
|
"""
|
|
|
|
@classmethod
|
|
def encode_json(cls, content):
|
|
return json.dumps(content, cls=DjangoJSONEncoder)
|
|
|
|
|
|
class KPsul(DjangoJsonWebsocketConsumer):
|
|
groups = ['kfet.kpsul']
|