account, schduels, timezone profile and many imporant updates

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-19 15:37:03 +00:00
parent 618ed8b8c6
commit e7219a2390
28 changed files with 919 additions and 358 deletions

View File

@@ -1944,29 +1944,39 @@ class AutomationViewSet(viewsets.ViewSet):
def server_time(self, request):
"""
GET /api/v1/automation/server_time/
Get current server time (UTC) used for all automation scheduling.
Get current time in the account timezone used for automation scheduling.
Returns:
- server_time: Current UTC timestamp (ISO 8601 format)
- server_time_formatted: Human-readable UTC time
- timezone: Server timezone setting (always UTC)
- server_time: Current timestamp (ISO 8601 format, account timezone)
- server_time_formatted: Human-readable time (account timezone)
- timezone: Account timezone setting
- celery_timezone: Celery task timezone setting
- use_tz: Whether Django is timezone-aware
Note: All automation schedules (scheduled_time) are in UTC.
When user sets "02:00", the automation runs at 02:00 UTC.
Note: Automation schedules are shown in the account timezone.
"""
from django.conf import settings
from zoneinfo import ZoneInfo
now = timezone.now()
account = getattr(request.user, 'account', None)
account_timezone = getattr(account, 'account_timezone', None) or 'UTC'
try:
tzinfo = ZoneInfo(account_timezone)
except Exception:
tzinfo = timezone.utc
account_timezone = 'UTC'
local_now = now.astimezone(tzinfo)
return Response({
'server_time': now.isoformat(),
'server_time_formatted': now.strftime('%H:%M'),
'server_time_date': now.strftime('%Y-%m-%d'),
'server_time_time': now.strftime('%H:%M:%S'),
'timezone': settings.TIME_ZONE,
'server_time': local_now.isoformat(),
'server_time_formatted': local_now.strftime('%H:%M'),
'server_time_date': local_now.strftime('%Y-%m-%d'),
'server_time_time': local_now.strftime('%H:%M:%S'),
'timezone': account_timezone,
'celery_timezone': getattr(settings, 'CELERY_TIMEZONE', settings.TIME_ZONE),
'use_tz': settings.USE_TZ,
'note': 'All automation schedules are in UTC. When you set "02:00", the automation runs at 02:00 UTC.'
'note': 'Automation schedules are shown in the account timezone.'
})