forked from DGNum/gestioCOF
1e18c4043e
- 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.
21 lines
488 B
Python
21 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']
|