Merge pull request #17 from ribaguifi/feature/language-selector

Update UI of language selector
This commit is contained in:
Santiago L 2022-02-28 19:05:45 +01:00 committed by GitHub
commit 872243a8c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 8 deletions

View File

@ -1,6 +1,7 @@
from django.contrib.auth.mixins import UserPassesTestMixin from django.contrib.auth.mixins import UserPassesTestMixin
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic.base import ContextMixin from django.views.generic.base import ContextMixin
from django.conf import settings
from . import api, get_version from . import api, get_version
from .auth import SESSION_KEY_TOKEN from .auth import SESSION_KEY_TOKEN
@ -20,6 +21,7 @@ class CustomContextMixin(ContextMixin):
context.update({ context.update({
'services_menu': services_menu, 'services_menu': services_menu,
'version': get_version(), 'version': get_version(),
'languages': settings.LANGUAGES,
}) })
return context return context

View File

@ -68,7 +68,7 @@
</div> </div>
</div> </div>
<div class="sidebar-logout"> <div class="sidebar-logout">
<ul class="nav flex-row"> <ul class="nav flex-row">
@ -87,6 +87,17 @@
</div> </div>
<div class="mt-4 pr-3 pb-2 text-light d-block text-right"> <div class="mt-4 pr-3 pb-2 text-light d-block text-right">
<div class="dropdown">
<a class="btn p-0 text-light" id="dropdownMenu3" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
<i class="fas fa-globe"></i> {% trans "Language" %}
</a>
<div class="dropdown-menu">
{% for code, language in languages %}
<a class="dropdown-item" href="{% url 'musician:profile-set-lang' code %}">{{ language }}</a>
{% endfor %}
</div>
</div>
<small>Panel Version {{ version }}</small> <small>Panel Version {{ version }}</small>
</div> </div>
{% endblock sidebar %} {% endblock sidebar %}
@ -102,7 +113,7 @@
</div> </div>
{% endfor %} {% endfor %}
{% endblock messages %} {% endblock messages %}
{% block content %} {% block content %}
{% endblock content %} {% endblock content %}
</div><!-- ./content --> </div><!-- ./content -->
</div><!-- ./wrapper --> </div><!-- ./wrapper -->

View File

@ -19,6 +19,7 @@ urlpatterns = [
path('billing/', views.BillingView.as_view(), name='billing'), path('billing/', views.BillingView.as_view(), name='billing'),
path('bills/<int:pk>/download/', views.BillDownloadView.as_view(), name='bill-download'), path('bills/<int:pk>/download/', views.BillDownloadView.as_view(), name='bill-download'),
path('profile/', views.ProfileView.as_view(), name='profile'), path('profile/', views.ProfileView.as_view(), name='profile'),
path('profile/setLang/<code>', views.profile_set_language, name='profile-set-lang'),
path('address/', views.MailView.as_view(), name='address-list'), path('address/', views.MailView.as_view(), name='address-list'),
path('address/new/', views.MailCreateView.as_view(), name='address-create'), path('address/new/', views.MailCreateView.as_view(), name='address-create'),
path('address/<int:pk>/', views.MailUpdateView.as_view(), name='address-update'), path('address/<int:pk>/', views.MailUpdateView.as_view(), name='address-update'),

View File

@ -1,13 +1,11 @@
import logging import logging
from os import stat
import smtplib import smtplib
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.mail import mail_managers 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.urls import reverse_lazy
from django.utils import translation from django.utils import translation
from django.utils.html import format_html from django.utils.html import format_html
@ -20,7 +18,7 @@ from django.views.generic.edit import DeleteView, FormView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from requests.exceptions import HTTPError from requests.exceptions import HTTPError
from . import api, get_version from . import get_version
from .auth import login as auth_login from .auth import login as auth_login
from .auth import logout as auth_logout from .auth import logout as auth_logout
from .forms import LoginForm, MailboxChangePasswordForm, MailboxCreateForm, MailboxUpdateForm, MailForm from .forms import LoginForm, MailboxChangePasswordForm, MailboxCreateForm, MailboxUpdateForm, MailForm
@ -85,7 +83,7 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
def get_mailbox_usage(self, profile_type): def get_mailbox_usage(self, profile_type):
allowed_mailboxes = ALLOWED_RESOURCES[profile_type]['mailbox'] allowed_mailboxes = ALLOWED_RESOURCES[profile_type]['mailbox']
total_mailboxes = len(self.orchestra.retrieve_mailbox_list()) total_mailboxes = len(self.orchestra.retrieve_mailbox_list())
mailboxes_left = allowed_mailboxes - total_mailboxes mailboxes_left = allowed_mailboxes - total_mailboxes
alert = '' alert = ''
if mailboxes_left < 0: if mailboxes_left < 0:
@ -126,6 +124,23 @@ class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
return context return context
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
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): class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin, ListView):
"""Base list view to all services""" """Base list view to all services"""
service_class = None service_class = None
@ -296,7 +311,6 @@ class MailingListsView(ServiceListView):
'title': _('Mailing lists'), 'title': _('Mailing lists'),
} }
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
domain_id = self.request.GET.get('domain') domain_id = self.request.GET.get('domain')