Let the user choose the language in his settings

This commit is contained in:
Oskar Hahn 2012-12-16 17:26:53 +01:00
parent 37d4c82434
commit 5ea863ca81
3 changed files with 11 additions and 4 deletions

View File

@ -88,12 +88,12 @@ TEMPLATE_LOADERS = (
) )
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'openslides.participant.middleware.AuthenticationMiddleware', 'openslides.participant.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
) )
ROOT_URLCONF = 'openslides.urls' ROOT_URLCONF = 'openslides.urls'

View File

@ -13,6 +13,7 @@
from django import forms from django import forms
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from openslides.utils.forms import ( from openslides.utils.forms import (
CssClassMixin, LocalizedModelMultipleChoiceField) CssClassMixin, LocalizedModelMultipleChoiceField)
@ -101,6 +102,8 @@ class GroupForm(forms.ModelForm, CssClassMixin):
class UsersettingsForm(forms.ModelForm, CssClassMixin): class UsersettingsForm(forms.ModelForm, CssClassMixin):
language = forms.ChoiceField(choices=settings.LANGUAGES)
class Meta: class Meta:
model = User model = User
fields = ('username', 'first_name', 'last_name', 'gender', 'email', 'committee', 'about_me') fields = ('username', 'first_name', 'last_name', 'gender', 'email', 'committee', 'about_me')

View File

@ -24,7 +24,7 @@ from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.views import login as django_login from django.contrib.auth.views import login as django_login
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils.translation import ugettext as _, ugettext_lazy from django.utils.translation import ugettext as _, ugettext_lazy, activate
from openslides.utils.pdf import stylesheet from openslides.utils.pdf import stylesheet
from openslides.utils.template import Tab from openslides.utils.template import Tab
@ -496,11 +496,15 @@ def user_settings(request):
form_user = UsersettingsForm(request.POST, instance=request.user) form_user = UsersettingsForm(request.POST, instance=request.user)
if form_user.is_valid(): if form_user.is_valid():
form_user.save() form_user.save()
language = request.LANGUAGE_CODE = \
request.session['django_language'] = form_user.cleaned_data['language']
activate(language)
messages.success(request, _('User settings successfully saved.')) messages.success(request, _('User settings successfully saved.'))
else: else:
messages.error(request, _('Please check the form for errors.')) messages.error(request, _('Please check the form for errors.'))
else: else:
form_user = UsersettingsForm(instance=request.user) language = request.session.get('django_language', request.LANGUAGE_CODE)
form_user = UsersettingsForm(instance=request.user, initial={'language': language})
return { return {
'form_user': form_user, 'form_user': form_user,