From 0d71d1be2974b9f8ed5d2288cfb580ae29084838 Mon Sep 17 00:00:00 2001 From: VladislavOstapov Date: Tue, 9 Jan 2024 18:30:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=20=D1=83=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BD=D1=8F=20=D0=B2=D0=BE=D0=B4=D1=8B=20"=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D1=8F=D0=B5=D1=82=D1=81=D1=8F"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index/views.py | 23 ++++++++++++++++++++++- ospaz_site/settings.py | 2 +- static/js/index-main.js | 10 ++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/index/views.py b/index/views.py index 30c608e..6c40a9b 100644 --- a/index/views.py +++ b/index/views.py @@ -1,8 +1,9 @@ import os -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render # from django.db.models import Manager +from django.contrib.auth import authenticate, login # только для тестирования! import requests @@ -12,6 +13,10 @@ TEST_BASE_FETCH = "https://test.wawaa.ru/dev-fetch.php" def view_index(request): return render(request, 'index.html') + # if request.user.is_authenticated: + # return render(request, 'index.html') + # else: + # return HttpResponseRedirect() def view_stats(request): @@ -29,3 +34,19 @@ def view_tank_chart(request): response = HttpResponse(res.content) response.headers["Content-type"] = response.headers["Content-type"] return response + + +# вход + + +def view_login(request): + username = request.POST["username"] + password = request.POST["password"] + user = authenticate(request, username=username, password=password) + if user is not None: + login(request, user) + return HttpResponseRedirect('/') + else: + # Return an 'invalid login' error message. + pass + diff --git a/ospaz_site/settings.py b/ospaz_site/settings.py index 838009e..2da3b64 100644 --- a/ospaz_site/settings.py +++ b/ospaz_site/settings.py @@ -28,7 +28,7 @@ PROJECT_ROOT = os.path.dirname(__file__) SECRET_KEY = os.getenv('DJANGO_SECRET') -ALLOWED_HOSTS = ['localhost', '10.8.0.2'] +ALLOWED_HOSTS = ['10.8.0.2'] # CSRF_TRUSTED_ORIGINS = ['https://ospaz.wawaa.ru'] # HTTPS settings https://docs.djangoproject.com/en/5.0/topics/security/ diff --git a/static/js/index-main.js b/static/js/index-main.js index a123f16..496c1db 100644 --- a/static/js/index-main.js +++ b/static/js/index-main.js @@ -165,7 +165,13 @@ async function updateStatus() { if (last_radar_values.length === 0) { document.getElementById("tank-level-dir").innerHTML = "(?)" } else { - document.getElementById("tank-level-dir").innerHTML = approximateWithTimestamps(last_radar_values) < 0 ? '↘' : '↗' + let ap = approximateWithTimestamps(last_radar_values) + if (Math.abs(ap) < 0.02) { + document.getElementById("tank-level-dir").innerHTML = '→' + } else { + document.getElementById("tank-level-dir").innerHTML = ap < 0 ? '↘' : '↗' + } + } //

Текущий уровень воды: %

@@ -211,7 +217,7 @@ async function updateStatus() { //

Состояние КА:

tmp = document.getElementById("pump-stage") if (dataset['pump']['pump_stage'] in pumpStageDescription) { - tmp.innerHTML = dataset['pump']['pump_stage'] + " (" + pumpStageDescription[dataset['pump']['vfd_err']] + ")" + tmp.innerHTML = dataset['pump']['pump_stage'] + " (" + pumpStageDescription[dataset['pump']['pump_stage']] + ")" } else { tmp.innerHTML = dataset['pump']['pump_stage'] }