перевел время на USE_TZ=True

This commit is contained in:
zakhy 2025-06-09 12:48:48 +07:00
parent 5a1d272cd3
commit 8f2b30365f
6 changed files with 25 additions and 21 deletions

View File

@ -23,7 +23,7 @@ from apps.gto.models.model_sensors import Sensors
from apps.gto.models.model_tracking import EquipmentTracking
from apps.gto.models.model_type_icons import ModelTypeIcons
from apps.util import generalmodule
from apps.util.datetime_funcs import get_current_time
from apps.util.datetime_funcs import get_current_time, convert_to_local_time
from sabron.util import logging
@ -80,8 +80,8 @@ def update_object(request):
"name": obj.equipment.name,
"lat": obj.lat,
"lon": obj.lon,
"time": obj.time.strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": obj.time.isoformat(),
"time": convert_to_local_time(obj.time).strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": convert_to_local_time(obj.time).isoformat(),
"statenum": obj.equipment.statenum,
"model": obj.equipment.model,
"icon": icons_map.get(obj.equipment.model.strip(), ""),
@ -114,8 +114,8 @@ def update_object(request):
"name": eq.name,
"lat": eq.lat,
"lon": eq.lon,
"time": eq.time.strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": eq.time.isoformat(),
"time": convert_to_local_time(eq.time).strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": convert_to_local_time(eq.time).isoformat(),
"statenum": eq.statenum,
"model": eq.model,
"icon": icons_map.get(eq.model.strip(), ""),

View File

@ -7,12 +7,14 @@ from django.core.paginator import Paginator
from django.db.models import Q
from django.http import JsonResponse
from django.shortcuts import redirect, render
from django.utils import timezone
from django.views.decorators.cache import never_cache
from pytz import utc
from apps.seismicproc.forms.form_earthquake import EarthquakeForm
from apps.seismicproc.models.model_earthquake import Earthquake
from apps.util import generalmodule
from apps.util.datetime_funcs import convert_to_local_time
from sabron.util import logging
@ -155,7 +157,7 @@ def earthquake_list(request):
time_filter = datetime.fromisoformat(time_filter).replace(
tzinfo=utc)
else:
time_filter = datetime.now()
time_filter = timezone.now()
time_filter_dif_week = time_filter - timedelta(days=7)
# Фильтрация землетрясений по дате
@ -167,8 +169,8 @@ def earthquake_list(request):
res.append(
{
"id": earthquake.id,
"time": earthquake.date_time.strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": earthquake.date_time.isoformat(),
"time": convert_to_local_time(earthquake.date_time).strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": convert_to_local_time(earthquake.date_time).isoformat(),
"lat": earthquake.latitude,
"lon": earthquake.longitude,
"depth": earthquake.depth,

View File

@ -1,3 +1,5 @@
import datetime
from django.conf import settings
from django.utils import timezone
@ -6,3 +8,7 @@ def get_current_time():
current_time = timezone.now()
current_time_timezoned = current_time.astimezone(settings.TIME_ZONE_OBJECT)
return current_time_timezoned
def convert_to_local_time(datetime_obj: datetime.datetime):
return datetime_obj.astimezone(settings.TIME_ZONE_OBJECT)

View File

@ -1,14 +1,11 @@
import json
import traceback
import zoneinfo
from datetime import datetime, timedelta
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.db.models import OuterRef, Subquery, Max
from django.db.models import Max
from django.http import JsonResponse
from django.shortcuts import render, get_object_or_404, redirect
from django.utils import timezone
from django.utils.timezone import utc
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
@ -17,8 +14,8 @@ from django.views.decorators.http import require_POST
from apps.general.views import settingsmodule
from apps.main.models.model_icons import Icons
from apps.util import generalmodule
from apps.util.datetime_funcs import get_current_time
from apps.util.natsort import natural_sort_key, get_priority
from apps.util.datetime_funcs import get_current_time, convert_to_local_time
from apps.util.natsort import get_priority
from apps.workerslocation.forms.form_worker import WorkerForm
from apps.workerslocation.models.workers_locations import WorkersLocation
from apps.workerslocation.models.workers_tracking import WorkersTracking
@ -136,8 +133,8 @@ def update_object(request, pk=None):
"name": name,
"lat": float(obj.latitude),
"lon": float(obj.longitude),
"time": obj.time.strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": obj.time.isoformat(),
"time": convert_to_local_time(obj.time).strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": convert_to_local_time(obj.time).isoformat(),
"condition": condition,
"active": worker.active,
"icon": icon
@ -169,8 +166,8 @@ def _prepare_worker_data(workers, icons_map, now):
"name": worker.name or worker.uid,
"lat": float(worker.latitude),
"lon": float(worker.longitude),
"time": worker.update_time.strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": worker.update_time.isoformat(),
"time": convert_to_local_time(worker.update_time).strftime("%d.%m.%Y %H:%M:%S"),
"iso_time": convert_to_local_time(worker.update_time).isoformat(),
"condition": worker.get_worker_condition(worker.update_time, now),
"active": worker.active,
"icon": icons_map.get(worker.icon_id)

View File

@ -6,7 +6,7 @@ TIME_ZONE_OBJECT = zoneinfo.ZoneInfo(TIME_ZONE)
UTC_TZ_OBJECT = zoneinfo.ZoneInfo("UTC")
USE_I18N = True
USE_L10N = True
USE_TZ = False
USE_TZ = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True

View File

@ -12,8 +12,7 @@ CELERY_RESULT_BACKEND = REDIS_URL
CELERY_ACCEPT_CONTENT = ["application/json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
# CELERY_TIMEZONE = TIME_ZONE
DJANGO_CELERY_BEAT_TZ_AWARE = False
CELERY_TIMEZONE = TIME_ZONE
CELERY_TASK_DEFAULT_QUEUE = "default"
# CELERY_TASK_TRACK_STARTED = True
# CELERY_TASK_TIME_LIMIT = 30 * 60