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

@@ -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)

View File

@@ -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)

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),

View File

@@ -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

View File

@@ -134,6 +134,14 @@
{% include 'blocks/b_footer.html' %}
<script>
let tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (!tz) {
tz = "UTC"
}
document.cookie = "user_tz=" + tz + ";path=/";
</script>
</body>
</body>

View File

@@ -1,6 +1,7 @@
{% load static %}
{% load tt_chat %}
{% load tz %}
{#{% load tz_detect %}#}
<div style="width: 100%;">
<div class="container-message_support_chat {% get_msg_side user ticket msg %}">
@@ -35,12 +36,13 @@
{% endif %}
</div>
<div class="data_send_message {% get_msg_side user ticket msg %}">
<span>{% if msg %}{{ msg.modifiedDT|localtime }}{% else %}{{ ticket.modifiedDT|localtime }}{% endif %}</span>
<span>{% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %}</span>
</div>
</div>
</div>
</div>
{#{% tz_detect %}#}
{#<div class="container-message_support_chat{% if msg.sender == ticket.manager %} left{% else %} right{% endif %}">#}
{# <div class="block_avatar_message">#}