0.12.24 timezone in chat messages

This commit is contained in:
SDE
2024-02-09 20:33:04 +03:00
parent a3ba6bc783
commit 3971a8ee23
10 changed files with 56 additions and 17 deletions

View File

@@ -9,8 +9,13 @@ class TimezoneMiddleware:
def __call__(self, request):
tz = request.COOKIES.get("user_tz")
if tz:
msg = f'user={str(request.user.id)} tz={str(tz)}'
print(msg)
if request.user.is_authenticated:
if not 'user_timezone' in request.user.user_profile.json_data or request.user.user_profile.json_data['user_timezone'] != tz:
request.user.user_profile.json_data['user_timezone'] = tz
request.user.user_profile.save(update_fields=['json_data'])
msg = f'user={str(request.user.id)} tz={str(tz)}'
print(msg)
timezone.activate(zoneinfo.ZoneInfo(tz))
else:
timezone.activate(zoneinfo.ZoneInfo("UTC"))