Merge pull request #14 from RubenPX/PR-4
#2 add language selector to web page
This commit is contained in:
commit
249a1182d4
|
@ -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
|
||||
|
|
|
@ -55,19 +55,43 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
{# <!-- user profile menu --> #}
|
||||
<div id="user-profile-menu" class="mt-5 pt-1 dropdown dropright">
|
||||
<button type="button" class="btn nav-link text-light w-100" data-toggle="dropdown">
|
||||
<div id="user-profile-menu" class="mt-5 pt-1">
|
||||
<button type="button" class="btn nav-link text-light w-100">
|
||||
<img id="user-avatar" class="float-right" width="64" height="64" src="{% static "musician/images/default-profile-picture.png" %}" alt="user-profile-picture"/>
|
||||
<strong>{{ profile.username }}</strong><br/>
|
||||
|
||||
<strong>{{ profile.username }}</strong><br />
|
||||
|
||||
<div class="dropdown">
|
||||
<a class="btn p-0 text-light" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
<i class="fas fa-cog"></i> {% trans "Settings" %}
|
||||
</button>
|
||||
</a>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="{% url 'musician:profile' %}"><i class="fas fa-user-circle"></i> {% trans 'Profile' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'musician:billing' %}"><i class="fas fa-receipt"></i> {% trans 'Billing' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'musician:profile' %}"><i class="fas fa-user-circle"></i> {% trans 'Profile'%}</a>
|
||||
<a class="dropdown-item" href="{% url 'musician:billing' %}"><i class="fas fa-receipt"></i> {% trans 'Billing'%}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dropdown">
|
||||
<a class="btn p-0 text-light" id="dropdownMenu2" 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>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="sidebar-logout">
|
||||
|
|
|
@ -19,6 +19,7 @@ urlpatterns = [
|
|||
path('billing/', views.BillingView.as_view(), name='billing'),
|
||||
path('bills/<int:pk>/download/', views.BillDownloadView.as_view(), name='bill-download'),
|
||||
path('profile/', views.ProfileView.as_view(), name='profile'),
|
||||
path('profile/setLang/<code>', 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/<int:pk>/', views.MailUpdateView.as_view(), name='address-update'),
|
||||
|
|
|
@ -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, 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):
|
||||
"""Base list view to all services"""
|
||||
|
|
Loading…
Reference in New Issue