diff --git a/openslides/global_settings.py b/openslides/global_settings.py index adb51aea7..94f900059 100644 --- a/openslides/global_settings.py +++ b/openslides/global_settings.py @@ -88,12 +88,12 @@ TEMPLATE_LOADERS = ( ) MIDDLEWARE_CLASSES = ( - 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'openslides.participant.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.locale.LocaleMiddleware', ) ROOT_URLCONF = 'openslides.urls' diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index 8085f313f..854abe91e 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -13,6 +13,7 @@ from django import forms from django.contrib.auth.models import Permission from django.utils.translation import ugettext_lazy as _ +from django.conf import settings from openslides.utils.forms import ( CssClassMixin, LocalizedModelMultipleChoiceField) @@ -101,6 +102,8 @@ class GroupForm(forms.ModelForm, CssClassMixin): class UsersettingsForm(forms.ModelForm, CssClassMixin): + language = forms.ChoiceField(choices=settings.LANGUAGES) + class Meta: model = User fields = ('username', 'first_name', 'last_name', 'gender', 'email', 'committee', 'about_me') diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 9081ec87b..bae5f0a69 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -24,7 +24,7 @@ from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.views import login as django_login from django.core.urlresolvers import reverse 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.template import Tab @@ -496,11 +496,15 @@ def user_settings(request): form_user = UsersettingsForm(request.POST, instance=request.user) if form_user.is_valid(): 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.')) else: messages.error(request, _('Please check the form for errors.')) 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 { 'form_user': form_user,