diff --git a/ChatServiceApp/funcs.py b/ChatServiceApp/funcs.py index 40f578f..ad85861 100644 --- a/ChatServiceApp/funcs.py +++ b/ChatServiceApp/funcs.py @@ -290,8 +290,6 @@ def get_chat_page_content_html(request, receiver_id=None): from AuthApp.models import User from django.utils import timezone - now = timezone.now() - msgs = [] try: cur_receiver = User.objects.get(id=receiver_id) diff --git a/GeneralApp/tz_middelware.py b/GeneralApp/tz_middelware.py deleted file mode 100644 index 0f6c539..0000000 --- a/GeneralApp/tz_middelware.py +++ /dev/null @@ -1,15 +0,0 @@ -import pytz - -from django.utils import timezone - -class TimezoneMiddleware: - def __init__(self, get_response): - self.get_response = get_response - - def __call__(self, request): - tzname = request.session.get('django_timezone') - if tzname: - timezone.activate(pytz.timezone(tzname)) - else: - timezone.deactivate() - return self.get_response(request) \ No newline at end of file diff --git a/TWB/settings.py b/TWB/settings.py index fb86856..cf81397 100644 --- a/TWB/settings.py +++ b/TWB/settings.py @@ -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/ diff --git a/TWB/tz_middelware.py b/TWB/tz_middelware.py new file mode 100644 index 0000000..4b58bd9 --- /dev/null +++ b/TWB/tz_middelware.py @@ -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) \ No newline at end of file diff --git a/TWB/urls.py b/TWB/urls.py index 45731c3..cd3a843 100644 --- a/TWB/urls.py +++ b/TWB/urls.py @@ -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), diff --git a/requirements.pip b/requirements.pip index ea31f0b..80e15ca 100644 --- a/requirements.pip +++ b/requirements.pip @@ -13,4 +13,5 @@ django-colorfield django-webpush==0.3.5 django-allauth==0.60.0 pytz==2024.1 +#django-tz-detect==0.4.0 diff --git a/templates/tb_base.html b/templates/tb_base.html index c55556b..23b9958 100644 --- a/templates/tb_base.html +++ b/templates/tb_base.html @@ -134,6 +134,14 @@ {% include 'blocks/b_footer.html' %} + + diff --git a/templates/widgets/w_message.html b/templates/widgets/w_message.html index b8955e2..9c3a250 100644 --- a/templates/widgets/w_message.html +++ b/templates/widgets/w_message.html @@ -1,6 +1,7 @@ {% load static %} {% load tt_chat %} -{% load tz %} +{#{% load tz_detect %}#} +
@@ -35,12 +36,13 @@ {% endif %}
- {% if msg %}{{ msg.modifiedDT|localtime }}{% else %}{{ ticket.modifiedDT|localtime }}{% endif %} + {% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %}
+{#{% tz_detect %}#} {#
#} {#
#}