From c2d021a516538424155459cec36f22c2a1f4caad Mon Sep 17 00:00:00 2001 From: SDE Date: Thu, 4 Apr 2024 23:16:26 +0300 Subject: [PATCH] 0.12.31 fix switch langs --- AuthApp/views.py | 7 ++++-- GeneralApp/funcs.py | 23 ++++++++++++------- static/js/authorization.js | 2 +- .../profile/w_button_for_profile_menu.html | 4 ++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/AuthApp/views.py b/AuthApp/views.py index f1c8393..6eac317 100644 --- a/AuthApp/views.py +++ b/AuthApp/views.py @@ -14,7 +14,7 @@ from datetime import datetime from django.contrib.auth.decorators import login_required from .funcs import * from GeneralApp.funcs import get_inter_http_respose -from django.urls import reverse +from GeneralApp.funcs import get_and_set_lang def registration_View(request): @@ -44,6 +44,9 @@ def registration_View(request): @login_required()#login_url='/profile/login/') def profile_page_View(request, page_name, id=None): + + lang = get_and_set_lang(request) + Dict = { 'page_html': get_profile_page_content_html(request, page_name, id), 'page_name': page_name, @@ -55,7 +58,7 @@ def profile_page_View(request, page_name, id=None): request.user.user_profile.save(update_fields=['mailing_on']) del request.session['mailingSubscribeRequired'] - title = f"{_('Личный кабинет пользователя')} {request.user.first_name} {request.user.last_name}" + title = _('Личный кабинет пользователя') + ' ' + request.user.first_name + ' ' + request.user.last_name Dict.update({ 'page': { diff --git a/GeneralApp/funcs.py b/GeneralApp/funcs.py index f0be41e..d4370b4 100644 --- a/GeneralApp/funcs.py +++ b/GeneralApp/funcs.py @@ -6,13 +6,18 @@ def get_and_set_lang(request): from django.utils.translation import activate, get_language lang = None - referer_url = request.META.get('HTTP_REFERER') - if referer_url: - url_list = referer_url.split('//') - if len(url_list) > 1: - url_list = url_list[1].split('/') - if len(url_list) > 1 and url_list[1] in settings.MODELTRANSLATION_LANGUAGES: - lang = url_list[1] + cur_url_list = request.path.split('/') + if len(cur_url_list) > 1 and cur_url_list[1] in settings.MODELTRANSLATION_LANGUAGES: + lang = cur_url_list[1] + + if not lang: + referer_url = request.META.get('HTTP_REFERER') + if referer_url: + url_list = referer_url.split('//') + if len(url_list) > 1: + url_list = url_list[1].split('/') + if len(url_list) > 1 and url_list[1] in settings.MODELTRANSLATION_LANGUAGES: + lang = url_list[1] if not lang: lang = get_language() @@ -20,7 +25,9 @@ def get_and_set_lang(request): if not lang: lang = 'en' - return activate(lang) + activate(lang) + + return lang diff --git a/static/js/authorization.js b/static/js/authorization.js index fb2f3be..723adb1 100644 --- a/static/js/authorization.js +++ b/static/js/authorization.js @@ -20,7 +20,7 @@ function SendLoginForm(el){ data: formData, success: function(data){ - location.href = `/profile/page/dashboard/` + location.href = data.redirect_url//`/profile/page/dashboard/` window.sessionStorage.removeItem('mailingSubscribeRequired') window.sessionStorage.removeItem('email') diff --git a/templates/widgets/profile/w_button_for_profile_menu.html b/templates/widgets/profile/w_button_for_profile_menu.html index c2aadb6..4d28593 100644 --- a/templates/widgets/profile/w_button_for_profile_menu.html +++ b/templates/widgets/profile/w_button_for_profile_menu.html @@ -9,14 +9,14 @@ {% if page_type and page_type == 'profile' or not sel_page_name %} {% if sel_page_name == 'logout' %} - + {% else %} {% endif %} {% else %} {% if sel_page_name == 'logout' %} - + {% elif sel_page_name != 'logoout' %}