From 0770f4bb964bf6e800ad5459ddea9b0c34dbcb3c Mon Sep 17 00:00:00 2001 From: zakhy Date: Fri, 30 May 2025 14:53:28 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=BD=D0=B0=20GET=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/gto/templates/gto_main.html | 5 +-- apps/gto/views/views_main.py | 53 ++++++++++++++--------------- apps/main/templates/main_index.html | 5 +-- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/apps/gto/templates/gto_main.html b/apps/gto/templates/gto_main.html index a89fb25..a891ccb 100644 --- a/apps/gto/templates/gto_main.html +++ b/apps/gto/templates/gto_main.html @@ -463,10 +463,7 @@ // Функция для обновления маркеров async function updateMarkers() { // Обновление GTO - const gtoData = await fetch('/gto/update_object/', { - method: 'POST', - headers: {'X-CSRFToken': csrftoken} - }).then(r => r.json()); + const gtoData = await fetch('/gto/update_object/').then(r => r.json()); gtoData.forEach(item => { if (gtoManager.markers[item.id]) { diff --git a/apps/gto/views/views_main.py b/apps/gto/views/views_main.py index d5d12c0..2685e74 100644 --- a/apps/gto/views/views_main.py +++ b/apps/gto/views/views_main.py @@ -26,34 +26,31 @@ from sabron.util import logging @never_cache def update_object(request): try: - if request.method == "POST": - now = timezone.now() - week_diff = now - timedelta(days=7) - object_list = Equipment.objects.filter(block=False, time__gt=week_diff).all() - m_list = [] - for obj in object_list: - type_g = obj.model.strip() - icon = "" - icon_obj = ModelTypeIcons.objects.filter(model=type_g).first() - if icon_obj is not None: - icon = icon_obj.icon.url - m_list.append( - { - "id": obj.id, - "name": obj.name, - "lat": obj.lat, - "lon": obj.lon, - "time": obj.time.strftime("%d.%m.%Y %H:%M:%S"), - "iso_time": obj.time.isoformat(), - "statenum": obj.statenum, - "model": obj.model, - "icon": icon, - "garagenum": obj.garagenum, - } - ) - return generalmodule.ReturnJson(200, m_list) - else: - return HttpResponse(status=405) + now = timezone.now() + week_diff = now - timedelta(days=7) + object_list = Equipment.objects.filter(block=False, time__gt=week_diff).all() + res = [] + for obj in object_list: + type_g = obj.model.strip() + icon = "" + icon_obj = ModelTypeIcons.objects.filter(model=type_g).first() + if icon_obj is not None: + icon = icon_obj.icon.url + res.append( + { + "id": obj.id, + "name": obj.name, + "lat": obj.lat, + "lon": obj.lon, + "time": obj.time.strftime("%d.%m.%Y %H:%M:%S"), + "iso_time": obj.time.isoformat(), + "statenum": obj.statenum, + "model": obj.model, + "icon": icon, + "garagenum": obj.garagenum, + } + ) + return JsonResponse(res, safe=False) except Exception as err: logging.error(traceback.format_exc()) diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html index 72e5e06..efd6a8e 100644 --- a/apps/main/templates/main_index.html +++ b/apps/main/templates/main_index.html @@ -229,10 +229,7 @@ // Функция для обновления маркеров async function updateMarkers() { // Обновление GTO - const gtoData = await fetch('/gto/update_object/', { - method: 'POST', - headers: {'X-CSRFToken': csrftoken} - }).then(r => r.json()); + const gtoData = await fetch('/gto/update_object/').then(r => r.json()); gtoData.forEach(item => { if (gtoManager.markers[item.id]) {