0.12.22 timezone in chat messages
This commit is contained in:
@@ -290,8 +290,6 @@ def get_chat_page_content_html(request, receiver_id=None):
|
|||||||
from AuthApp.models import User
|
from AuthApp.models import User
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
now = timezone.now()
|
|
||||||
|
|
||||||
msgs = []
|
msgs = []
|
||||||
try:
|
try:
|
||||||
cur_receiver = User.objects.get(id=receiver_id)
|
cur_receiver = User.objects.get(id=receiver_id)
|
||||||
|
|||||||
@@ -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)
|
|
||||||
@@ -126,7 +126,8 @@ MIDDLEWARE = [
|
|||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
'AuthApp.middleware.ResponseInterceptionMiddleware',
|
'AuthApp.middleware.ResponseInterceptionMiddleware',
|
||||||
'GeneralApp.tz_middelware.TimezoneMiddleware',
|
'TWB.tz_middelware.TimezoneMiddleware',
|
||||||
|
# 'tz_detect.middleware.TimezoneMiddleware',
|
||||||
|
|
||||||
"allauth.account.middleware.AccountMiddleware",
|
"allauth.account.middleware.AccountMiddleware",
|
||||||
]
|
]
|
||||||
@@ -221,11 +222,11 @@ TIME_ZONE = 'Europe/Minsk'
|
|||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
USE_TZ = True
|
# USE_TZ = True
|
||||||
|
|
||||||
USE_L10N = True
|
USE_L10N = True
|
||||||
|
|
||||||
# USE_TZ = False
|
USE_TZ = False
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||||
|
|||||||
17
TWB/tz_middelware.py
Normal file
17
TWB/tz_middelware.py
Normal 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)
|
||||||
@@ -13,6 +13,8 @@ urlpatterns = [
|
|||||||
path('ckeditor/', include('ckeditor_uploader.urls')),
|
path('ckeditor/', include('ckeditor_uploader.urls')),
|
||||||
path('i18n/', include('django.conf.urls.i18n')),
|
path('i18n/', include('django.conf.urls.i18n')),
|
||||||
|
|
||||||
|
# path('tz_detect/', include('tz_detect.urls')),
|
||||||
|
|
||||||
path('accounts/signup/', login_View, name='signup'),
|
path('accounts/signup/', login_View, name='signup'),
|
||||||
path('accounts/login/cancelled/', login_View),
|
path('accounts/login/cancelled/', login_View),
|
||||||
|
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ django-colorfield
|
|||||||
django-webpush==0.3.5
|
django-webpush==0.3.5
|
||||||
django-allauth==0.60.0
|
django-allauth==0.60.0
|
||||||
pytz==2024.1
|
pytz==2024.1
|
||||||
|
#django-tz-detect==0.4.0
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,14 @@
|
|||||||
|
|
||||||
{% include 'blocks/b_footer.html' %}
|
{% 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>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load tt_chat %}
|
{% load tt_chat %}
|
||||||
{% load tz %}
|
{#{% load tz_detect %}#}
|
||||||
|
|
||||||
|
|
||||||
<div style="width: 100%;">
|
<div style="width: 100%;">
|
||||||
<div class="container-message_support_chat {% get_msg_side user ticket msg %}">
|
<div class="container-message_support_chat {% get_msg_side user ticket msg %}">
|
||||||
@@ -35,12 +36,13 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="data_send_message {% get_msg_side user ticket msg %}">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#{% tz_detect %}#}
|
||||||
|
|
||||||
{#<div class="container-message_support_chat{% if msg.sender == ticket.manager %} left{% else %} right{% endif %}">#}
|
{#<div class="container-message_support_chat{% if msg.sender == ticket.manager %} left{% else %} right{% endif %}">#}
|
||||||
{# <div class="block_avatar_message">#}
|
{# <div class="block_avatar_message">#}
|
||||||
|
|||||||
Reference in New Issue
Block a user