From 84eab062e8903c663148045ad8fef9d2d5c8650a Mon Sep 17 00:00:00 2001 From: Sabron Date: Thu, 15 Feb 2024 11:34:57 +0700 Subject: [PATCH] update : 15.02.2024 11:34:57,43 --- apps/main/templates/main_index.html | 9 +- apps/montorem/__init__.py | 1 + apps/montorem/admin.py | 3 + apps/montorem/apps.py | 7 + apps/montorem/migrations/__init__.py | 1 + apps/montorem/templates/montorem_index.html | 255 ++++++++++++++++++++ apps/montorem/templates/sensor_index.html | 220 +++++++++++++++++ apps/montorem/urls.py | 12 + apps/montorem/views/views_main.py | 88 +++++++ repcofkk/app_settings.py | 3 +- repcofkk/urls.py | 1 + templates/default.html | 20 +- templates/registration/login.html | 2 +- 13 files changed, 616 insertions(+), 6 deletions(-) create mode 100644 apps/montorem/__init__.py create mode 100644 apps/montorem/admin.py create mode 100644 apps/montorem/apps.py create mode 100644 apps/montorem/migrations/__init__.py create mode 100644 apps/montorem/templates/montorem_index.html create mode 100644 apps/montorem/templates/sensor_index.html create mode 100644 apps/montorem/urls.py create mode 100644 apps/montorem/views/views_main.py diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html index 70bf5a3..6398ca2 100644 --- a/apps/main/templates/main_index.html +++ b/apps/main/templates/main_index.html @@ -8,11 +8,18 @@
- SCADA + SCADA
+
+
+
+ Montorem +
+
+
diff --git a/apps/montorem/__init__.py b/apps/montorem/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/apps/montorem/__init__.py @@ -0,0 +1 @@ + diff --git a/apps/montorem/admin.py b/apps/montorem/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/apps/montorem/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/apps/montorem/apps.py b/apps/montorem/apps.py new file mode 100644 index 0000000..29d9573 --- /dev/null +++ b/apps/montorem/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class MontoremConfig(AppConfig): + name = 'apps.montorem' + verbose_name = "Монторем" + diff --git a/apps/montorem/migrations/__init__.py b/apps/montorem/migrations/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/apps/montorem/migrations/__init__.py @@ -0,0 +1 @@ + diff --git a/apps/montorem/templates/montorem_index.html b/apps/montorem/templates/montorem_index.html new file mode 100644 index 0000000..02ec9a5 --- /dev/null +++ b/apps/montorem/templates/montorem_index.html @@ -0,0 +1,255 @@ +{% extends "default.html" %} +{% load static %} +{% load mysettings %} + + +{% block header_link %} + +{% endblock header_link %} + + +{% block content %} +
+
+
+

Плотномеры

+ +
+
+
+
+
+ + + +
+
+
+
+
+

Список датчиков

+
+
+
+ +
+ + + + + + + + + + + + {% for sensor in sensor_list %} + + + + + + + + {% endfor %} + + +
+
+
+ +
+
+ + +{% endblock %} + +{% block script_footer %} + + +{% endblock script_footer %} diff --git a/apps/montorem/templates/sensor_index.html b/apps/montorem/templates/sensor_index.html new file mode 100644 index 0000000..f4766ff --- /dev/null +++ b/apps/montorem/templates/sensor_index.html @@ -0,0 +1,220 @@ +{% extends "default.html" %} +{% load static %} +{% load mysettings %} + + +{% block header_link %} + +{% endblock header_link %} + + +{% block content %} +
+ +
+ + +
+
+
+ +
+ +
+

График изменения ({{sensor.unit}})

+ +
+ +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+

Показания датчика

+
+
+
+ +
+ + + + + + + + + + {% for sensor in sensor_list %} + + + + + + {% endfor %} + + +
+
+
+ +
+
+{% endblock %} + +{% block script_footer %} + + + + +{% endblock script_footer %} diff --git a/apps/montorem/urls.py b/apps/montorem/urls.py new file mode 100644 index 0000000..6cf17d7 --- /dev/null +++ b/apps/montorem/urls.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +from django.conf.urls import url +from django.contrib.auth.decorators import login_required +from django.conf.urls import include # Используйте include() чтобы добавлять URL из каталога приложения + +from apps.montorem.views import views_main + +urlpatterns = [ + url(r'^$', views_main.mainindex, name='mainindex'), + url(r'^sensor/$', views_main.sensor, name='sensor'), + url(r'sensor/sensor_ajax/$', views_main.sensor_ajax, name='sensor_ajax'), + ] diff --git a/apps/montorem/views/views_main.py b/apps/montorem/views/views_main.py new file mode 100644 index 0000000..ee9d84d --- /dev/null +++ b/apps/montorem/views/views_main.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +import traceback +import datetime +import requests +import base64 +import json + +from datetime import datetime +from requests.auth import HTTPBasicAuth +from django.conf import settings +from django.db.models import Q +from django.shortcuts import render +from django.http import HttpResponse +from django.conf import settings +from django.shortcuts import redirect +from django.contrib.auth.decorators import login_required +from django.views.decorators.cache import never_cache +from django.db.models import Avg, Max, Min + + +from apps.util import generalmodule +from sabron.util import logging + + +@login_required(login_url='/accounts/login/?next=') +@never_cache +def mainindex(request): + try: + if request.method == "GET": + response = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor_list',auth=('user_api', 'qwerty*1')) + js = response.json() + if js['status'] == 0: + context={ + 'updatepage':True, + 'sensor_list':js['respose'], + } + else: + context={ + 'updatepage':True, + } + return render(request, 'montorem_index.html',context) + except Exception as err: + logging.error(traceback.format_exc()) + +@login_required(login_url='/accounts/login/?next=') +@never_cache +def sensor(request): + try: + if request.method == "GET": + get_param=request.GET.dict() + response_sensor = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor&id='+get_param['id'],auth=('user_api', 'qwerty*1')) + sensor = response_sensor.json() + response = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor_readings&id='+get_param['id'],auth=('user_api', 'qwerty*1')) + js = response.json() + if js['status'] == 0: + context={ + 'sensor':sensor['respose'], + 'sensor_list':js['respose'], + } + else: + context={ + 'updatepage':True, + } + return render(request, 'sensor_index.html',context) + except Exception as err: + logging.error(traceback.format_exc()) + + +@login_required(login_url='/accounts/login/?next=') +@never_cache +def sensor_ajax(request): + try: + if request.method == "POST": + m_sensor=[] + sensor_dict = dict() + param = request.POST.dict() + print(param) + response_sensor = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor&id='+param['id'],auth=('user_api', 'qwerty*1')) + sensor = response_sensor.json() + #connect_time = sensor['connect_time'] + #value = sensor['value'] + response = requests.get('http://192.168.10.3/api/v1/json/montorem/?method=sensor_readings&id='+param['id']+'&sensor_type='+param['sensor_type'],auth=('user_api', 'qwerty*1')) + sensor_list = response.json() + print(sensor_list['respose']) + return generalmodule.ReturnJson(200,sensor_list['respose']) + + except Exception as err: + logging.error(traceback.format_exc()) \ No newline at end of file diff --git a/repcofkk/app_settings.py b/repcofkk/app_settings.py index 86af685..c4cd51d 100644 --- a/repcofkk/app_settings.py +++ b/repcofkk/app_settings.py @@ -18,12 +18,13 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'apps.main.apps.MainConfig', # Стартовая страница + 'apps.montorem.apps.MontoremConfig', # Подсистема монторем ] """Информация о приложении """ SITE_TITLE = u'Система отчетов' SITE_TITLE_S = u'СиО' -APP_VER = u'1.0.0.7' +APP_VER = u'1.0.0.9' APP_VEK = u'2024 г' APP_COPPIRIGHT = u'Система отчетов' diff --git a/repcofkk/urls.py b/repcofkk/urls.py index 93db8d5..27d4e66 100644 --- a/repcofkk/urls.py +++ b/repcofkk/urls.py @@ -12,6 +12,7 @@ from . import views urlpatterns = [ url(r'^$', RedirectView.as_view(url='/main/', permanent=True)), #Перенаправляет все запросы url(r'^main/', include('apps.main.urls')), + url(r'^montorem/', include('apps.montorem.urls')), url(r'^accounts/logout/', views.user_logout, name='user_logout'), url(r'^accounts/', views.user_login, name='user_login'), diff --git a/templates/default.html b/templates/default.html index 9df2e3e..63fd98f 100644 --- a/templates/default.html +++ b/templates/default.html @@ -108,7 +108,7 @@
@@ -293,7 +307,7 @@ - + {% block script_footer %} {% endblock script_footer %} diff --git a/templates/registration/login.html b/templates/registration/login.html index 32092fa..f116f61 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -31,7 +31,7 @@