Перевел методы на GET запрос

This commit is contained in:
zakhy 2025-05-30 14:53:28 +07:00
parent ebb539fd55
commit 0770f4bb96
3 changed files with 27 additions and 36 deletions

View File

@ -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]) {

View File

@ -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())

View File

@ -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]) {