Merge branch '1-language-preference'

Closes #1.
This commit is contained in:
Santiago Lamora 2020-01-23 17:45:32 +01:00
commit 4b9f401c4c
7 changed files with 47 additions and 16 deletions

View File

@ -17,5 +17,6 @@ class LoginForm(AuthenticationForm):
else: else:
self.username = username self.username = username
self.token = orchestra.auth_token self.token = orchestra.auth_token
self.user = orchestra.retrieve_profile()
return self.cleaned_data return self.cleaned_data

View File

@ -109,14 +109,20 @@ class UserAccount(OrchestraModel):
@classmethod @classmethod
def new_from_json(cls, data, **kwargs): def new_from_json(cls, data, **kwargs):
billing = None billing = None
language = None
last_login = None last_login = None
if 'billcontact' in data: if 'billcontact' in data:
billing = BillingContact.new_from_json(data['billcontact']) 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: if 'last_login' in data:
last_login = parse_datetime(data['last_login']) 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): class DatabaseUser(OrchestraModel):

View File

@ -43,6 +43,9 @@ a:hover {
min-width: 280px; min-width: 280px;
max-width: 280px; max-width: 280px;
min-height: 100vh; min-height: 100vh;
position: fixed;
z-index: 999;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -127,6 +130,7 @@ a:hover {
background-position: right 5% top 10%; background-position: right 5% top 10%;
color: #343434; color: #343434;
padding-left: 2rem; padding-left: 2rem;
margin-left: 280px; /** sidebar width **/
} }
/** services **/ /** services **/

View File

@ -4,7 +4,7 @@
{% block content %} {% block content %}
<h1 class="service-name">{% trans "Billing" %}</h1> <h1 class="service-name">{% trans "Billing" %}</h1>
<p class="service-description">Little description of what to be expected...</p> <p class="service-description">{% trans "Little description of what billing section is." %}</p>
<table class="table service-list"> <table class="table service-list">
<colgroup> <colgroup>
@ -16,11 +16,11 @@
</colgroup> </colgroup>
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th scope="col">Number</th> <th scope="col">{% trans "Number" %}</th>
<th scope="col">Bill date</th> <th scope="col">{% trans "Bill date" %}</th>
<th scope="col">Type</th> <th scope="col">{% trans "Type" %}</th>
<th scope="col">Total</th> <th scope="col">{% trans "Total" %}</th>
<th scope="col">Download PDF</th> <th scope="col">{% trans "Download PDF" %}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

@ -3,12 +3,12 @@
{% block content %} {% block content %}
<h1 class="service-name">Profile</h1> <h1 class="service-name">{% trans "Profile" %}</h1>
<p class="service-description">Little description of what to be expected...</p> <p class="service-description">{% trans "Little description of what profile section is." %}</p>
<div class="card-deck"> <div class="card-deck">
<div class="card card-profile"> <div class="card card-profile">
<h5 class="card-header">User information</h5> <h5 class="card-header">{% trans "User information" %}</h5>
<div class="card-body row"> <div class="card-body row">
<div class="col-md"> <div class="col-md">
<div class="border-primary rounded-circle d-inline-block p-1" style="background-color: white; border: 5px solid grey"> <div class="border-primary rounded-circle d-inline-block p-1" style="background-color: white; border: 5px solid grey">
@ -18,12 +18,12 @@
<div class="col-md-9"> <div class="col-md-9">
<p class="card-text">{{ profile.username }}</p> <p class="card-text">{{ profile.username }}</p>
<p class="card-text">{{ profile.type }}</p> <p class="card-text">{{ profile.type }}</p>
<p class="card-text">Preferred language: {{ profile.language }}</p> <p class="card-text">{% trans "Preferred language:" %} {{ profile.language|language_name_local }}</p>
</div> </div>
{% comment %} {% comment %}
<!-- disabled until set_password is implemented --> <!-- disabled until set_password is implemented -->
<div class="col-md-12 text-right"> <div class="col-md-12 text-right">
<a class="btn btn-primary pl-5 pr-5" href="#">Set new password</a> <a class="btn btn-primary pl-5 pr-5" href="#">{% trans "Set new password" %}</a>
</div> </div>
{% endcomment %} {% endcomment %}
</div> </div>
@ -31,7 +31,7 @@
{% with profile.billing as contact %} {% with profile.billing as contact %}
<div class="card card-profile"> <div class="card card-profile">
<h5 class="card-header">Billing information</h5> <h5 class="card-header">{% trans "Billing information" %}</h5>
<div class="card-body"> <div class="card-body">
<div class="form-group">{{ contact.name }}</div> <div class="form-group">{{ contact.name }}</div>
<div class="form-group">{{ contact.address }}</div> <div class="form-group">{{ contact.address }}</div>
@ -45,7 +45,7 @@
</div> </div>
<!-- payment method --> <!-- payment method -->
<div class="form-group"> <div class="form-group">
payment method: {{ payment.method }} {% trans "payment method:" %} {{ payment.method }}
</div> </div>
<div class="form-group"> <div class="form-group">
{% if payment.method == 'SEPADirectDebit' %} {% if payment.method == 'SEPADirectDebit' %}

View File

@ -1,9 +1,11 @@
from itertools import groupby from itertools import groupby
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render 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.http import is_safe_url from django.utils.http import is_safe_url
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View from django.views import View
@ -305,7 +307,15 @@ class LoginView(FormView):
def form_valid(self, form): def form_valid(self, form):
"""Security check complete. Log the user in.""" """Security check complete. Log the user in."""
auth_login(self.request, form.username, form.token) 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): def get_success_url(self):
url = self.get_redirect_url() url = self.get_redirect_url()

View File

@ -13,7 +13,10 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
import os import os
from decouple import config, Csv from decouple import config, Csv
from django.utils.translation import gettext_lazy as _
from dj_database_url import parse as db_url from dj_database_url import parse as db_url
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -56,6 +59,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
@ -126,7 +130,13 @@ SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/ # 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' TIME_ZONE = 'UTC'