Let the user choose the language in his settings
This commit is contained in:
parent
37d4c82434
commit
5ea863ca81
@ -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'
|
||||
|
@ -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')
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user