diff --git a/musician/forms.py b/musician/forms.py index 5fcafbe..7a66a00 100644 --- a/musician/forms.py +++ b/musician/forms.py @@ -17,5 +17,6 @@ class LoginForm(AuthenticationForm): else: self.username = username self.token = orchestra.auth_token + self.user = orchestra.retrieve_profile() return self.cleaned_data diff --git a/musician/models.py b/musician/models.py index a0c058f..a9b9698 100644 --- a/musician/models.py +++ b/musician/models.py @@ -109,14 +109,20 @@ class UserAccount(OrchestraModel): @classmethod def new_from_json(cls, data, **kwargs): billing = None + language = None last_login = None if 'billcontact' in data: billing = BillingContact.new_from_json(data['billcontact']) + # Django expects that language code is lowercase + if 'language' in data: + language = data['language'].lower() + if 'last_login' in data: last_login = parse_datetime(data['last_login']) - return super().new_from_json(data=data, billing=billing, last_login=last_login) + + return super().new_from_json(data=data, billing=billing, language=language, last_login=last_login) class DatabaseUser(OrchestraModel): diff --git a/musician/static/musician/css/default.css b/musician/static/musician/css/default.css index a95a573..3fbe7da 100644 --- a/musician/static/musician/css/default.css +++ b/musician/static/musician/css/default.css @@ -43,6 +43,9 @@ a:hover { min-width: 280px; max-width: 280px; min-height: 100vh; + + position: fixed; + z-index: 999; display: flex; flex-direction: column; @@ -127,6 +130,7 @@ a:hover { background-position: right 5% top 10%; color: #343434; padding-left: 2rem; + margin-left: 280px; /** sidebar width **/ } /** services **/ diff --git a/musician/templates/musician/billing.html b/musician/templates/musician/billing.html index 46d1396..f181341 100644 --- a/musician/templates/musician/billing.html +++ b/musician/templates/musician/billing.html @@ -4,7 +4,7 @@ {% block content %}

{% trans "Billing" %}

-

Little description of what to be expected...

+

{% trans "Little description of what billing section is." %}

@@ -16,11 +16,11 @@ - - - - - + + + + + diff --git a/musician/templates/musician/profile.html b/musician/templates/musician/profile.html index 6a49dd6..44c57ab 100644 --- a/musician/templates/musician/profile.html +++ b/musician/templates/musician/profile.html @@ -3,12 +3,12 @@ {% block content %} -

Profile

-

Little description of what to be expected...

+

{% trans "Profile" %}

+

{% trans "Little description of what profile section is." %}

-
User information
+
{% trans "User information" %}
@@ -18,12 +18,12 @@

{{ profile.username }}

{{ profile.type }}

-

Preferred language: {{ profile.language }}

+

{% trans "Preferred language:" %} {{ profile.language|language_name_local }}

{% comment %} {% endcomment %}
@@ -31,7 +31,7 @@ {% with profile.billing as contact %}
-
Billing information
+
{% trans "Billing information" %}
{{ contact.name }}
{{ contact.address }}
@@ -45,7 +45,7 @@
- payment method: {{ payment.method }} + {% trans "payment method:" %} {{ payment.method }}
{% if payment.method == 'SEPADirectDebit' %} diff --git a/musician/views.py b/musician/views.py index e96fa24..102a66d 100644 --- a/musician/views.py +++ b/musician/views.py @@ -1,9 +1,11 @@ from itertools import groupby +from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render from django.urls import reverse_lazy +from django.utils import translation from django.utils.http import is_safe_url from django.utils.translation import gettext_lazy as _ from django.views import View @@ -305,7 +307,15 @@ class LoginView(FormView): def form_valid(self, form): """Security check complete. Log the user in.""" auth_login(self.request, form.username, form.token) - return HttpResponseRedirect(self.get_success_url()) + + # set user language as active language + user_language = form.user.language + translation.activate(user_language) + + response = HttpResponseRedirect(self.get_success_url()) + response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_language) + + return response def get_success_url(self): url = self.get_redirect_url() diff --git a/userpanel/settings.py b/userpanel/settings.py index d14b228..cb5ce35 100644 --- a/userpanel/settings.py +++ b/userpanel/settings.py @@ -13,7 +13,10 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ import os from decouple import config, Csv +from django.utils.translation import gettext_lazy as _ from dj_database_url import parse as db_url + + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -56,6 +59,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -126,7 +130,13 @@ SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies" # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = config('LANGUAGE_CODE', 'en-us') + +LANGUAGES = [ + ('ca', _('Catalan')), + ('en', _('English')), + ('es', _('Spanish')), +] TIME_ZONE = 'UTC'
NumberBill dateTypeTotalDownload PDF{% trans "Number" %}{% trans "Bill date" %}{% trans "Type" %}{% trans "Total" %}{% trans "Download PDF" %}