From 2f47a9e3db4129a2c887d7146e8dc841bc20a713 Mon Sep 17 00:00:00 2001 From: SDE Date: Thu, 8 Feb 2024 14:51:19 +0300 Subject: [PATCH 1/7] 0.12.18 registration mail to user --- AuthApp/js_views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index 1aa7683..83773ab 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -444,7 +444,7 @@ def login_ajax(request): -def send_registration_mail(data_Dict): +def send_registration_mail(data_Dict, user): try: @@ -463,7 +463,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 +518,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']) From eddb3a18582c9f3dfc65a503ac0d7dc8771583ff Mon Sep 17 00:00:00 2001 From: SDE Date: Fri, 9 Feb 2024 15:12:10 +0300 Subject: [PATCH 2/7] 0.12.19 timezone in chat messages --- templates/widgets/w_message.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/widgets/w_message.html b/templates/widgets/w_message.html index d5244aa..b8955e2 100644 --- a/templates/widgets/w_message.html +++ b/templates/widgets/w_message.html @@ -1,5 +1,6 @@ {% load static %} {% load tt_chat %} +{% load tz %}
@@ -34,7 +35,7 @@ {% endif %}
- {% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %} + {% if msg %}{{ msg.modifiedDT|localtime }}{% else %}{{ ticket.modifiedDT|localtime }}{% endif %}
From a25f30eda7f94fbcc82e076b64204e3ca97f24cb Mon Sep 17 00:00:00 2001 From: SDE Date: Fri, 9 Feb 2024 16:57:27 +0300 Subject: [PATCH 3/7] 0.12.20 timezone in chat messages --- ChatServiceApp/funcs.py | 3 +++ GeneralApp/tz_middelware.py | 15 +++++++++++++++ TWB/settings.py | 5 +++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 GeneralApp/tz_middelware.py diff --git a/ChatServiceApp/funcs.py b/ChatServiceApp/funcs.py index ea5c475..40f578f 100644 --- a/ChatServiceApp/funcs.py +++ b/ChatServiceApp/funcs.py @@ -288,6 +288,9 @@ def send_msg(data): 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: diff --git a/GeneralApp/tz_middelware.py b/GeneralApp/tz_middelware.py new file mode 100644 index 0000000..0f6c539 --- /dev/null +++ b/GeneralApp/tz_middelware.py @@ -0,0 +1,15 @@ +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 5e3738b..fb86856 100644 --- a/TWB/settings.py +++ b/TWB/settings.py @@ -126,6 +126,7 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'AuthApp.middleware.ResponseInterceptionMiddleware', + 'GeneralApp.tz_middelware.TimezoneMiddleware', "allauth.account.middleware.AccountMiddleware", ] @@ -220,11 +221,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/ From 713695cf7d16438cded79928b255f162e0d363e9 Mon Sep 17 00:00:00 2001 From: SDE Date: Fri, 9 Feb 2024 17:00:28 +0300 Subject: [PATCH 4/7] 0.12.21 timezone in chat messages --- requirements.pip | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.pip b/requirements.pip index 75932d7..ea31f0b 100644 --- a/requirements.pip +++ b/requirements.pip @@ -12,4 +12,5 @@ channels-redis==4.1.0 django-colorfield django-webpush==0.3.5 django-allauth==0.60.0 +pytz==2024.1 From b87df027146e3475a0c2dee9416e571443802847 Mon Sep 17 00:00:00 2001 From: SDE Date: Fri, 9 Feb 2024 18:01:11 +0300 Subject: [PATCH 5/7] 0.12.22 timezone in chat messages --- ChatServiceApp/funcs.py | 2 -- GeneralApp/tz_middelware.py | 15 --------------- TWB/settings.py | 7 ++++--- TWB/tz_middelware.py | 17 +++++++++++++++++ TWB/urls.py | 2 ++ requirements.pip | 1 + templates/tb_base.html | 8 ++++++++ templates/widgets/w_message.html | 6 ++++-- 8 files changed, 36 insertions(+), 22 deletions(-) delete mode 100644 GeneralApp/tz_middelware.py create mode 100644 TWB/tz_middelware.py 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 %}#} {#
#} {#
#} From a3ba6bc783c2a39baf35379205631b0d2a5015c8 Mon Sep 17 00:00:00 2001 From: SDE Date: Fri, 9 Feb 2024 18:18:21 +0300 Subject: [PATCH 6/7] 0.12.23 timezone in chat messages --- ChatServiceApp/funcs.py | 3 +++ templates/widgets/w_message.html | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChatServiceApp/funcs.py b/ChatServiceApp/funcs.py index ad85861..14baba2 100644 --- a/ChatServiceApp/funcs.py +++ b/ChatServiceApp/funcs.py @@ -290,6 +290,9 @@ def get_chat_page_content_html(request, receiver_id=None): from AuthApp.models import User from django.utils import timezone + msg = f'now {timezone.now()}' + print(msg) + msgs = [] try: cur_receiver = User.objects.get(id=receiver_id) diff --git a/templates/widgets/w_message.html b/templates/widgets/w_message.html index 9c3a250..5fd117b 100644 --- a/templates/widgets/w_message.html +++ b/templates/widgets/w_message.html @@ -1,6 +1,6 @@ {% load static %} {% load tt_chat %} -{#{% load tz_detect %}#} +{% load tz %}
@@ -36,7 +36,7 @@ {% endif %}
- {% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %} + {% if msg %}{{ msg.modifiedDT|localtime }}{% else %}{{ ticket.modifiedDT|localtime }}{% endif %}
From 3971a8ee23ce4bdbd9a4c162db2910234ed844d3 Mon Sep 17 00:00:00 2001 From: SDE Date: Fri, 9 Feb 2024 20:33:04 +0300 Subject: [PATCH 7/7] 0.12.24 timezone in chat messages --- AuthApp/funcs.py | 14 ++++++++++++++ AuthApp/js_views.py | 1 + AuthApp/models.py | 6 ++++++ ChatServiceApp/funcs.py | 14 ++++++-------- ChatServiceApp/js_views.py | 4 +++- TWB/tz_middelware.py | 9 +++++++-- templates/blocks/profile/b_messages_container.html | 6 ++++-- templates/widgets/w_file.html | 5 ++++- templates/widgets/w_message.html | 6 +++++- templates/widgets/w_request_tech_support.html | 8 ++++++-- 10 files changed, 56 insertions(+), 17 deletions(-) diff --git a/AuthApp/funcs.py b/AuthApp/funcs.py index aa77bc8..ab412bd 100644 --- a/AuthApp/funcs.py +++ b/AuthApp/funcs.py @@ -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 diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index 83773ab..d064ff9 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -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) diff --git a/AuthApp/models.py b/AuthApp/models.py index 3ed08e8..56e0d9b 100644 --- a/AuthApp/models.py +++ b/AuthApp/models.py @@ -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: diff --git a/ChatServiceApp/funcs.py b/ChatServiceApp/funcs.py index 14baba2..4df1ded 100644 --- a/ChatServiceApp/funcs.py +++ b/ChatServiceApp/funcs.py @@ -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,10 +288,7 @@ def send_msg(data): def get_chat_page_content_html(request, receiver_id=None): from AuthApp.models import User - from django.utils import timezone - - msg = f'now {timezone.now()}' - print(msg) + from AuthApp.funcs import get_user_timezone_Dict msgs = [] try: @@ -311,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) diff --git a/ChatServiceApp/js_views.py b/ChatServiceApp/js_views.py index 1a13962..c896c34 100644 --- a/ChatServiceApp/js_views.py +++ b/ChatServiceApp/js_views.py @@ -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: diff --git a/TWB/tz_middelware.py b/TWB/tz_middelware.py index 4b58bd9..5c22305 100644 --- a/TWB/tz_middelware.py +++ b/TWB/tz_middelware.py @@ -9,8 +9,13 @@ class TimezoneMiddleware: def __call__(self, request): tz = request.COOKIES.get("user_tz") if tz: - msg = f'user={str(request.user.id)} tz={str(tz)}' - print(msg) + 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")) diff --git a/templates/blocks/profile/b_messages_container.html b/templates/blocks/profile/b_messages_container.html index 1af33bd..f7aab90 100644 --- a/templates/blocks/profile/b_messages_container.html +++ b/templates/blocks/profile/b_messages_container.html @@ -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 %} - + {% timezone user_tz %} + + {% endtimezone %} {% endif %} {% endfor %} {% endif %} diff --git a/templates/widgets/w_file.html b/templates/widgets/w_file.html index e0fb852..bf11392 100644 --- a/templates/widgets/w_file.html +++ b/templates/widgets/w_file.html @@ -1,5 +1,6 @@ {% load static %} {% load tt_chat %} +{% load tz %}
@@ -20,7 +21,9 @@
- {% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %} + {% timezone user_tz %} + {% if msg %}{{ msg.modifiedDT }}{% else %}{{ ticket.modifiedDT }}{% endif %} + {% endtimezone %}
diff --git a/templates/widgets/w_message.html b/templates/widgets/w_message.html index 5fd117b..cf3525b 100644 --- a/templates/widgets/w_message.html +++ b/templates/widgets/w_message.html @@ -36,7 +36,11 @@ {% endif %}
- {% if msg %}{{ msg.modifiedDT|localtime }}{% else %}{{ ticket.modifiedDT|localtime }}{% endif %} + {% timezone user_tz %} + + {% if msg %}{{ msg.modifiedDT|localtime }}{% else %}{{ ticket.modifiedDT|localtime }}{% endif %} + + {% endtimezone %}
diff --git a/templates/widgets/w_request_tech_support.html b/templates/widgets/w_request_tech_support.html index 5d94897..bdd56de 100644 --- a/templates/widgets/w_request_tech_support.html +++ b/templates/widgets/w_request_tech_support.html @@ -1,5 +1,8 @@ {% load static %} {% load i18n %} +{% load tz %} + +
@@ -10,8 +13,9 @@ {# #} {# 10.02.2023#} - {{ ticket.modifiedDT|date:"d.m.Y" }} - + {% timezone user_tz %} + {{ ticket.modifiedDT|date:"d.m.Y" }} + {% endtimezone %}