Merge remote-tracking branch 'origin/main'

This commit is contained in:
2024-02-12 16:09:24 +03:00
14 changed files with 91 additions and 14 deletions

View File

@@ -1,5 +1,19 @@
from django.template.loader import render_to_string
def get_user_timezone_Dict(user, request=None):
tz = None
if request:
tz = request.COOKIES.get("user_tz")
if not tz and user.is_authenticated:
tz = user.user_profile.get_timezone()
if not tz:
from django.conf import settings
tz = settings.TIME_ZONE
return {'user_tz': tz}
def get_dashboard_page_content_html(request):
from ChatServiceApp.funcs import get_unanswered_msgs_count_for_user

View File

@@ -232,6 +232,7 @@ def chats_ajax(request):
'receivers': receivers,
# 'messages': cur_chat_msgs
}
Dict.update(get_user_timezone_Dict(request.user, request=request))
html = render_to_string('blocks/profile/b_chats.html', Dict, request=request)
return JsonResponse({'html': html}, status=200)
@@ -444,7 +445,7 @@ def login_ajax(request):
def send_registration_mail(data_Dict):
def send_registration_mail(data_Dict, user):
try:
@@ -463,7 +464,7 @@ def send_registration_mail(data_Dict):
html = render_to_string('mail/m_registration.html', Dict)
from BaseModels.mailSender import admin_send_mail_by_SMTPlib
mail_sets = get_mail_send_options()
to = [mail_sets['sender_email'], 'web@syncsystems.net', 'sa@a3-global.com', 'sysadmin.hax@gmail.com']
to = [user.email, 'web@syncsystems.net', 'sa@a3-global.com', 'sysadmin.hax@gmail.com']
res = admin_send_mail_by_SMTPlib(
mail_sets,
subject=subject,
@@ -518,7 +519,7 @@ def registration_ajax(request):
'user': user,
'pass': form.data['password']
}
res = send_registration_mail(mail_Dict)
res = send_registration_mail(mail_Dict, user)
res_Dict = {
'redirect_url': reverse('profile_page', args=['dashboard'])

View File

@@ -53,6 +53,12 @@ class UserProfile(BaseModel):
mailing_on = models.BooleanField(default=False, verbose_name=_('Рассылка'))
def get_timezone(self):
tz = None
if 'user_timezone' in self.json_data:
tz = self.json_data['user_timezone']
return tz
def save_user_alerts_to_session(self, request):
for_save_to_session = self.get_node_by_name('for_save_to_session')
if for_save_to_session:

View File

@@ -13,7 +13,7 @@ from django.urls import reverse
import json
from datetime import datetime, time
from django.conf import settings
from AuthApp.funcs import get_user_timezone_Dict
def get_unanswered_msgs_count_for_user(user):
@@ -56,7 +56,6 @@ def get_update_chat_Dict(data):
if data['sender'] == data['cur_user']:
user = copy.copy(sender)
cur_receiver = copy.copy(receiver)
# context_Dict.update({'user': sender})
else:
user = copy.copy(receiver)
cur_receiver = copy.copy(sender)
@@ -65,8 +64,9 @@ def get_update_chat_Dict(data):
# context_Dict.update({'cur_receiver': receiver})
context_Dict.update({
'cur_receiver': cur_receiver,
'user': user
'user': user,
})
context_Dict.update(get_user_timezone_Dict(user))
if sender == receiver:
print('!')
@@ -112,7 +112,7 @@ def get_update_chat_Dict(data):
context_Dict.update({
'messages': msgs,
'MEDIA_URL': settings.MEDIA_URL
'MEDIA_URL': settings.MEDIA_URL,
})
html = render_to_string(tpl_name, context_Dict)
if required_full_support_chat_html:
@@ -288,6 +288,7 @@ def send_msg(data):
def get_chat_page_content_html(request, receiver_id=None):
from AuthApp.models import User
from AuthApp.funcs import get_user_timezone_Dict
msgs = []
try:
@@ -307,6 +308,7 @@ def get_chat_page_content_html(request, receiver_id=None):
'receivers': receivers,
'page': 'chat',
}
Dict.update(get_user_timezone_Dict(request.user, request=request))
tpl_name = 'blocks/profile/b_chats.html'
html = render_to_string(tpl_name, Dict, request=request)

View File

@@ -53,6 +53,7 @@ def show_chat_w_user_ajax(request):
data = json.loads(request.body)
Dict = get_chat_page_content_Dict(request, data['user_id'])
Dict.update(get_user_timezone_Dict(request.user, request=request))
tpl_name = 'blocks/profile/b_chats.html'
@@ -99,7 +100,7 @@ def update_chat_ajax2(request):
receiver = User.objects.get(id=data['receiver'])
context_Dict.update({'cur_receiver': receiver})
context_Dict.update(get_user_timezone_Dict(request.user, request=request))
if not ticket:
@@ -190,6 +191,7 @@ def update_chat_ajax(request):
receiver = User.objects.get(id=data['receiver'])
context_Dict.update({'cur_receiver': receiver})
context_Dict.update(get_user_timezone_Dict(request.user, request=request))
if ticket:

View File

@@ -126,6 +126,8 @@ MIDDLEWARE = [
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'AuthApp.middleware.ResponseInterceptionMiddleware',
'TWB.tz_middelware.TimezoneMiddleware',
# 'tz_detect.middleware.TimezoneMiddleware',
"allauth.account.middleware.AccountMiddleware",
]

22
TWB/tz_middelware.py Normal file
View File

@@ -0,0 +1,22 @@
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:
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"))
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

@@ -12,4 +12,6 @@ channels-redis==4.1.0
django-colorfield
django-webpush==0.3.5
django-allauth==0.60.0
pytz==2024.1
#django-tz-detect==0.4.0

View File

@@ -1,5 +1,5 @@
{% load static %}
{% load tz %}
{#{% include "widgets/w_file.html" %}#}
{% if not messages and ticket %}
@@ -8,7 +8,9 @@
{% for msg in messages %}
{% include "widgets/w_message.html" %}
{% if forloop.first %}
<span style="display: none" class="date_n_time_last_message" data-modifiedDT="{{ msg.modifiedDT|date:"d.m.Y H:i:s:u" }}"></span>
{% timezone user_tz %}
<span style="display: none" class="date_n_time_last_message" data-modifiedDT="{{ msg.modifiedDT|date:"d.m.Y H:i:s:u" }}"></span>
{% endtimezone %}
{% endif %}
{% endfor %}
{% endif %}

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,5 +1,6 @@
{% load static %}
{% load tt_chat %}
{% load tz %}
<div style="width: 100%;">
<div class="container-message_support_chat {% get_msg_side user ticket msg %}">
@@ -20,7 +21,9 @@
</div>
</div>
<div class="data_send_message {% get_msg_side user ticket msg %}">
<span>{% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %}</span>
{% timezone user_tz %}
<span>{% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %}</span>
{% endtimezone %}
</div>
</div>
</div>

View File

@@ -1,5 +1,7 @@
{% load static %}
{% load tt_chat %}
{% load tz %}
<div style="width: 100%;">
<div class="container-message_support_chat {% get_msg_side user ticket msg %}">
@@ -34,12 +36,17 @@
{% endif %}
</div>
<div class="data_send_message {% get_msg_side user ticket msg %}">
<span>{% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %}</span>
{% timezone user_tz %}
<span>
{% if msg %}{{ msg.modifiedDT|localtime }}{% else %}{{ ticket.modifiedDT|localtime }}{% endif %}
</span>
{% endtimezone %}
</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">#}

View File

@@ -1,5 +1,8 @@
{% load static %}
{% load i18n %}
{% load tz %}
<div class="container-message-req-sprt" onclick="openTicket({{ ticket.id }})">
<div class="message-sprt-inf">
<div>
@@ -10,8 +13,9 @@
{# <img>#}
<span id="modified_date">
{# 10.02.2023#}
{{ ticket.modifiedDT|date:"d.m.Y" }}
{% timezone user_tz %}
{{ ticket.modifiedDT|date:"d.m.Y" }}
{% endtimezone %}
</span>
</div>