From a8c3ab7403acfa4c7d0d31403f341815f076b09e Mon Sep 17 00:00:00 2001 From: Patrick Maeght Date: Wed, 18 Jul 2018 14:03:50 +0200 Subject: [PATCH] weather query --- src/dashboard/views.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+), 0 deletions(-) diff --git a/src/dashboard/views.py b/src/dashboard/views.py index 9035878..7dadc09 100644 --- a/src/dashboard/views.py +++ b/src/dashboard/views.py @@ -129,6 +129,31 @@ def weather(request): return render(request, 'dashboard/reload_weather.html', {'base_template' : "base_unlogged.html"}) def weather_current(request): + # PM 20180718 + if request.is_ajax(): + try: + weather_status = WeatherWatch.objects.latest('updated') + plc_device_status = PlcDeviceStatus.objects.exclude(plc_mode=None).latest('created') + plc_mode = plc_device_status.plc_mode + is_safe = plc_device_status.is_safe + weather = serializers.serialize('json', [weather_status]) + weather = json.loads(weather) + ack = Config.objects.get(id=1).ack + plc_timeout = Config.objects.get(pk=1).plc_timeout_seconds + timeout = (datetime.datetime.now() - plc_device_status.created).total_seconds() + weather[0]['max_sunelev'] = SUN_ELEV_DAY_THRESHOLD + weather[0]['sunelev'] = get_sunelev() + weather[0]["plc_mode"] = plc_mode + weather[0]["is_safe"] = is_safe + weather[0]["ACK"] = ack + weather[0]["plc_timeout"] = timeout + weather[0]["max_plc_timeout"] = plc_timeout + weather[0]["pyros_mode"] = Config.objects.get(id=1).pyros_state + return HttpResponse(json.dumps(weather), content_type="application/json") + except WeatherWatch.DoesNotExist: + raise Http404("No WeatherWatch matches the given query.") + +def weather_current_old(request): try: if (len(Config.objects.all()) == 1): monitoring = int(int(Config.objects.get(id=1).row_data_save_frequency) / 5) -- libgit2 0.21.2