0.12.22 timezone in chat messages

This commit is contained in:
SDE
2024-02-09 18:01:11 +03:00
parent 713695cf7d
commit b87df02714
8 changed files with 36 additions and 22 deletions

View File

@@ -126,7 +126,8 @@ MIDDLEWARE = [
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'AuthApp.middleware.ResponseInterceptionMiddleware',
'GeneralApp.tz_middelware.TimezoneMiddleware',
'TWB.tz_middelware.TimezoneMiddleware',
# 'tz_detect.middleware.TimezoneMiddleware',
"allauth.account.middleware.AccountMiddleware",
]
@@ -221,11 +222,11 @@ TIME_ZONE = 'Europe/Minsk'
USE_I18N = True
USE_TZ = True
# USE_TZ = True
USE_L10N = True
# USE_TZ = False
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

17
TWB/tz_middelware.py Normal file
View File

@@ -0,0 +1,17 @@
import zoneinfo
from django.utils import timezone
from django.shortcuts import render
class TimezoneMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
tz = request.COOKIES.get("user_tz")
if tz:
msg = f'user={str(request.user.id)} tz={str(tz)}'
print(msg)
timezone.activate(zoneinfo.ZoneInfo(tz))
else:
timezone.activate(zoneinfo.ZoneInfo("UTC"))
return self.get_response(request)

View File

@@ -13,6 +13,8 @@ urlpatterns = [
path('ckeditor/', include('ckeditor_uploader.urls')),
path('i18n/', include('django.conf.urls.i18n')),
# path('tz_detect/', include('tz_detect.urls')),
path('accounts/signup/', login_View, name='signup'),
path('accounts/login/cancelled/', login_View),