From e051631a34bdaf91188e437f1276db31bc434499 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 5 Apr 2017 09:28:32 -0300 Subject: [PATCH] Use WebSocket classes --- kfet/templates/kfet/account_read.html | 12 +----------- kfet/templates/kfet/transfers.html | 13 +------------ kfet/views.py | 2 +- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/kfet/templates/kfet/account_read.html b/kfet/templates/kfet/account_read.html index 7decefc2..3974e0a2 100644 --- a/kfet/templates/kfet/account_read.html +++ b/kfet/templates/kfet/account_read.html @@ -13,7 +13,6 @@ - {% if account.user == request.user %} @@ -115,16 +114,7 @@ $(document).ready(function() { // Synchronization // ----- - var websocket_msg_default = {'opegroups':[],'opes':[]} - - var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; - var location_host = window.location.host; - var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host; - var socket = new ReconnectingWebSocket(websocket_protocol+"://" + location_url + "/ws/k-fet/k-psul/"); - socket.onmessage = function(e) { - var data = $.extend({}, websocket_msg_default, JSON.parse(e.data)); - history.update_data(data); - } + OperationWebSocket.add_handler((data) => history.update_data(data)); Config.reset(history.reset.bind(history)); }); diff --git a/kfet/templates/kfet/transfers.html b/kfet/templates/kfet/transfers.html index 15a546a9..088228d8 100644 --- a/kfet/templates/kfet/transfers.html +++ b/kfet/templates/kfet/transfers.html @@ -63,18 +63,7 @@ $(document).ready(function() { // Synchronization // ----- - - var websocket_msg_default = {'opes':[]} - - var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; - var location_host = window.location.host; - var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host; - var socket = new ReconnectingWebSocket(websocket_protocol+"://" + location_url + "/ws/k-fet/k-psul/"); - socket.onmessage = function(e) { - var data = $.extend({}, websocket_msg_default, JSON.parse(e.data)); - history.update_data(data); - - } + OperationWebSocket.add_handler((data) => history.update_data(data)); Config.reset(history.reset.bind(history)); }); diff --git a/kfet/views.py b/kfet/views.py index 7ff4a59e..b7d47022 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -17,7 +17,7 @@ from django.http import JsonResponse, Http404 from django.forms import formset_factory from django.forms.models import model_to_dict from django.db import transaction -from django.db.models import F, Sum, Prefetch, Count +from django.db.models import Q, F, Sum, Prefetch, Count from django.db.models.functions import Coalesce from django.utils import timezone from django.utils.crypto import get_random_string