def update_chat(**kwargs): channel_layer = get_channel_layer() message = kwargs["instance"] response = { "item": get_model_serializer(Message, [])(message).data, "itemId": message.id, "itemIndex": message.id } async_to_sync(channel_layer.group_send)("participants", {"type": "send.json","text": json.dumps({"type": "CHAT_ITEMS_ADD", "payload": response})})
def item_data(model, data, excluded = []): response = { "items": {}, "itemsOrder": [] } for item in data: response["items"][item.id] = get_model_serializer(model, excluded)(item).data response["itemsOrder"].append(item.id) return(response)
class ThresholdViewSet(viewsets.ModelViewSet): queryset = Threshold.objects.all() serializer_class = get_model_serializer(Threshold, field_exceptions)
class EventViewSet(viewsets.ModelViewSet): queryset = Event.objects.all() serializer_class = get_model_serializer(Event, field_exceptions + ["threshold", "resourceeventstate"])
class SessionViewSet(viewsets.ModelViewSet): queryset = Session.objects.all() serializer_class = get_model_serializer(Session, field_exceptions + ["participant", "resourceeventstate", "chatsession"])
class ScoreViewSet(viewsets.ModelViewSet): queryset = Score.objects.all() serializer_class = get_model_serializer(Score, field_exceptions + ["participant"])
class ScenarioViewSet(viewsets.ModelViewSet): queryset = Scenario.objects.all() serializer_class = get_model_serializer(Scenario, field_exceptions + ["briefing", "session"])
class ResourceDepotViewSet(viewsets.ModelViewSet): queryset = ResourceDepot.objects.all() serializer_class = get_model_serializer(ResourceDepot, field_exceptions)