From 6b7cad86f2850f54b8da9b4e50b1e5477afddc8b Mon Sep 17 00:00:00 2001 From: RubenPX Date: Sat, 12 Feb 2022 03:29:42 +0100 Subject: [PATCH 1/5] add launguage selector to web page (only visual) --- musician/templates/musician/base.html | 65 ++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/musician/templates/musician/base.html b/musician/templates/musician/base.html index e8cf514..beca2b9 100644 --- a/musician/templates/musician/base.html +++ b/musician/templates/musician/base.html @@ -55,22 +55,51 @@ {% endfor %} + + {# #} - + + + + + + {% block script %} From feb591ea79064bd7452f88a2072065ae6cffb928 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Thu, 24 Feb 2022 22:09:17 +0100 Subject: [PATCH 2/5] Add URL and detect if languague exist --- musician/urls.py | 1 + musician/views.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/musician/urls.py b/musician/urls.py index c4402e2..b549a59 100644 --- a/musician/urls.py +++ b/musician/urls.py @@ -19,6 +19,7 @@ urlpatterns = [ path('billing/', views.BillingView.as_view(), name='billing'), path('bills//download/', views.BillDownloadView.as_view(), name='bill-download'), path('profile/', views.ProfileView.as_view(), name='profile'), + path('profile/setLang/', views.ProfileSetLang, name='profile'), path('address/', views.MailView.as_view(), name='address-list'), path('address/new/', views.MailCreateView.as_view(), name='address-create'), path('address//', views.MailUpdateView.as_view(), name='address-update'), diff --git a/musician/views.py b/musician/views.py index 663f498..58d8819 100644 --- a/musician/views.py +++ b/musician/views.py @@ -1,3 +1,4 @@ +from audioop import reverse import logging from os import stat import smtplib @@ -6,7 +7,7 @@ from django.conf import settings from django.contrib import messages from django.core.exceptions import ImproperlyConfigured from django.core.mail import mail_managers -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponse, HttpResponseNotFound, HttpResponseRedirect from django.shortcuts import render from django.urls import reverse_lazy from django.utils import translation @@ -125,6 +126,22 @@ class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): return context +def ProfileSetLang(request, lang): + # set user language as active language + + if any(x[0] == lang for x in settings.LANGUAGES): + # http://127.0.0.1:8080/profile/setLang/es + user_language = lang + translation.activate(user_language) + + response = HttpResponseRedirect('/dashboard') + response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_language) + + return response + else: + response = HttpResponseNotFound('Languague not found') + return response + class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin, ListView): """Base list view to all services""" From 1816301952b3e44b8c2e288e40d46dd9c389f6fc Mon Sep 17 00:00:00 2001 From: RubenPX Date: Sat, 26 Feb 2022 19:54:27 +0100 Subject: [PATCH 3/5] aded full functionality to lang menu --- musician/mixins.py | 2 ++ musician/templates/musician/base.html | 6 +++--- musician/urls.py | 2 +- musician/views.py | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/musician/mixins.py b/musician/mixins.py index ba54587..6368467 100644 --- a/musician/mixins.py +++ b/musician/mixins.py @@ -1,6 +1,7 @@ from django.contrib.auth.mixins import UserPassesTestMixin from django.utils.translation import gettext_lazy as _ from django.views.generic.base import ContextMixin +from django.conf import settings from . import api, get_version from .auth import SESSION_KEY_TOKEN @@ -20,6 +21,7 @@ class CustomContextMixin(ContextMixin): context.update({ 'services_menu': services_menu, 'version': get_version(), + 'languages': settings.LANGUAGES, }) return context diff --git a/musician/templates/musician/base.html b/musician/templates/musician/base.html index beca2b9..b049cb0 100644 --- a/musician/templates/musician/base.html +++ b/musician/templates/musician/base.html @@ -81,9 +81,9 @@ {% trans "Language" %} diff --git a/musician/urls.py b/musician/urls.py index b549a59..9b4c0ca 100644 --- a/musician/urls.py +++ b/musician/urls.py @@ -19,7 +19,7 @@ urlpatterns = [ path('billing/', views.BillingView.as_view(), name='billing'), path('bills//download/', views.BillDownloadView.as_view(), name='bill-download'), path('profile/', views.ProfileView.as_view(), name='profile'), - path('profile/setLang/', views.ProfileSetLang, name='profile'), + path('profile/setLang/', views.ProfileSetLang, name='profile-set-lang'), path('address/', views.MailView.as_view(), name='address-list'), path('address/new/', views.MailCreateView.as_view(), name='address-create'), path('address//', views.MailUpdateView.as_view(), name='address-update'), diff --git a/musician/views.py b/musician/views.py index 58d8819..38cb794 100644 --- a/musician/views.py +++ b/musician/views.py @@ -126,12 +126,12 @@ class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): return context -def ProfileSetLang(request, lang): +def ProfileSetLang(request, code): # set user language as active language - if any(x[0] == lang for x in settings.LANGUAGES): + if any(x[0] == code for x in settings.LANGUAGES): # http://127.0.0.1:8080/profile/setLang/es - user_language = lang + user_language = code translation.activate(user_language) response = HttpResponseRedirect('/dashboard') From 66530351adef77d4c7bee01b9f485f5b0f2a4cca Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 28 Feb 2022 19:01:32 +0100 Subject: [PATCH 4/5] Move language selector to bottom of the sidebar --- musician/templates/musician/base.html | 55 ++++++++++----------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/musician/templates/musician/base.html b/musician/templates/musician/base.html index 3d4a1ec..bfe3258 100644 --- a/musician/templates/musician/base.html +++ b/musician/templates/musician/base.html @@ -55,44 +55,20 @@ {% endfor %} - - {# #} -
- + {{ profile.username }}
+ {% trans "Settings" %} + +
- - -
+ Panel Version {{ version }}
{% endblock sidebar %} @@ -126,7 +113,7 @@ {% endfor %} {% endblock messages %} - {% block content %} + {% block content %} {% endblock content %} From 19f5229536515bbae36a58fd9d6025b39592c956 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 28 Feb 2022 19:05:06 +0100 Subject: [PATCH 5/5] Fix flake8 issues --- musician/urls.py | 2 +- musician/views.py | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/musician/urls.py b/musician/urls.py index 9b4c0ca..a00ead2 100644 --- a/musician/urls.py +++ b/musician/urls.py @@ -19,7 +19,7 @@ urlpatterns = [ path('billing/', views.BillingView.as_view(), name='billing'), path('bills//download/', views.BillDownloadView.as_view(), name='bill-download'), path('profile/', views.ProfileView.as_view(), name='profile'), - path('profile/setLang/', views.ProfileSetLang, name='profile-set-lang'), + path('profile/setLang/', views.profile_set_language, name='profile-set-lang'), path('address/', views.MailView.as_view(), name='address-list'), path('address/new/', views.MailCreateView.as_view(), name='address-create'), path('address//', views.MailUpdateView.as_view(), name='address-update'), diff --git a/musician/views.py b/musician/views.py index 38cb794..626f2c2 100644 --- a/musician/views.py +++ b/musician/views.py @@ -1,6 +1,4 @@ -from audioop import reverse import logging -from os import stat import smtplib from django.conf import settings @@ -8,7 +6,6 @@ from django.contrib import messages from django.core.exceptions import ImproperlyConfigured from django.core.mail import mail_managers from django.http import HttpResponse, HttpResponseNotFound, HttpResponseRedirect -from django.shortcuts import render from django.urls import reverse_lazy from django.utils import translation from django.utils.html import format_html @@ -21,7 +18,7 @@ from django.views.generic.edit import DeleteView, FormView from django.views.generic.list import ListView from requests.exceptions import HTTPError -from . import api, get_version +from . import get_version from .auth import login as auth_login from .auth import logout as auth_logout from .forms import LoginForm, MailboxChangePasswordForm, MailboxCreateForm, MailboxUpdateForm, MailForm @@ -86,7 +83,7 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): def get_mailbox_usage(self, profile_type): allowed_mailboxes = ALLOWED_RESOURCES[profile_type]['mailbox'] total_mailboxes = len(self.orchestra.retrieve_mailbox_list()) - mailboxes_left = allowed_mailboxes - total_mailboxes + mailboxes_left = allowed_mailboxes - total_mailboxes alert = '' if mailboxes_left < 0: @@ -126,9 +123,10 @@ class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): return context -def ProfileSetLang(request, code): + +def profile_set_language(request, code): # set user language as active language - + if any(x[0] == code for x in settings.LANGUAGES): # http://127.0.0.1:8080/profile/setLang/es user_language = code @@ -313,7 +311,6 @@ class MailingListsView(ServiceListView): 'title': _('Mailing lists'), } - def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) domain_id = self.request.GET.get('domain')