diff --git a/modoboa/core/__init__.py b/modoboa/core/__init__.py index 7b9f6ba3f..641809b03 100644 --- a/modoboa/core/__init__.py +++ b/modoboa/core/__init__.py @@ -54,10 +54,9 @@ def load_core_settings(): This function must be manually called (see :file:`urls.py`) in order to load base settings. """ - from modoboa.core.app_settings import GeneralParametersForm, UserSettings + from modoboa.core.app_settings import GeneralParametersForm parameters.register(GeneralParametersForm, ugettext_lazy("General")) - parameters.register(UserSettings, ugettext_lazy("General")) events.declare(BASE_EVENTS) diff --git a/modoboa/core/app_settings.py b/modoboa/core/app_settings.py index e73a5fa53..648f02215 100644 --- a/modoboa/core/app_settings.py +++ b/modoboa/core/app_settings.py @@ -357,33 +357,3 @@ class GeneralParametersForm(parameters.AdminParametersForm): }) else: settings.AUTH_LDAP_GLOBAL_OPTIONS[ldap.OPT_REFERRALS] = False - - -def translate_language_code(value): - if "-" in value: - return value.split("-")[0] - return value - - -class UserSettings(parameters.UserParametersForm): - app = "core" - - sep = SeparatorField(label=ugettext_lazy("Display")) - - lang = forms.ChoiceField( - initial=translate_language_code(settings.LANGUAGE_CODE), - label=ugettext_lazy("Prefered language"), - choices=[("cs", "čeština"), - ("de", "deutsch"), - ("en", "english"), - ("es", "español"), - ("fr", "français"), - ("it", "italiano"), - ("nl", "nederlands"), - ("pt_PT", "português"), - ("pt_BR", "português (BR)"), - ("ru", "русский"), - ("sv", "svenska")], - help_text=ugettext_lazy("Prefered language to display pages"), - widget=forms.Select(attrs={"class": "form-control"}) - ) diff --git a/modoboa/core/constants.py b/modoboa/core/constants.py new file mode 100644 index 000000000..4a7f669ea --- /dev/null +++ b/modoboa/core/constants.py @@ -0,0 +1,18 @@ +# coding: utf-8 + +"""Core application constants.""" + + +LANGUAGES = ( + ("cs", u"čeština"), + ("de", u"deutsch"), + ("en", u"english"), + ("es", u"español"), + ("fr", u"français"), + ("it", u"italiano"), + ("nl", u"nederlands"), + ("pt_PT", u"português"), + ("pt_BR", u"português (BR)"), + ("ru", u"русский"), + ("sv", u"svenska"), +) diff --git a/modoboa/core/forms.py b/modoboa/core/forms.py index 2a35c7b6e..c1d96aa28 100644 --- a/modoboa/core/forms.py +++ b/modoboa/core/forms.py @@ -27,6 +27,9 @@ class LoginForm(forms.Form): class ProfileForm(forms.ModelForm): + + """Form to update User profile.""" + oldpassword = forms.CharField( label=ugettext_lazy("Old password"), required=False, widget=forms.PasswordInput(attrs={"class": "form-control"}) @@ -42,7 +45,7 @@ class ProfileForm(forms.ModelForm): class Meta: model = User - fields = ("first_name", "last_name") + fields = ("first_name", "last_name", "language") widgets = { 'first_name': forms.TextInput(attrs={'class': 'form-control'}), 'last_name': forms.TextInput(attrs={'class': 'form-control'}) diff --git a/modoboa/core/migrations/0005_user_language.py b/modoboa/core/migrations/0005_user_language.py new file mode 100644 index 000000000..3f61578ca --- /dev/null +++ b/modoboa/core/migrations/0005_user_language.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0004_auto_20150728_1228'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='language', + field=models.CharField(default=b'en', help_text='Prefered language to display pages.', max_length=10, choices=[(b'cs', '\u010de\u0161tina'), (b'de', 'deutsch'), (b'en', 'english'), (b'es', 'espa\xf1ol'), (b'fr', 'fran\xe7ais'), (b'it', 'italiano'), (b'nl', 'nederlands'), (b'pt_PT', 'portugu\xeas'), (b'pt_BR', 'portugu\xeas (BR)'), (b'ru', '\u0440\u0443\u0441\u0441\u043a\u0438\u0439'), (b'sv', 'svenska')]), + preserve_default=True, + ), + ] diff --git a/modoboa/core/models.py b/modoboa/core/models.py index e407814b3..3b965bc3c 100644 --- a/modoboa/core/models.py +++ b/modoboa/core/models.py @@ -23,6 +23,8 @@ from modoboa.lib.exceptions import ( PermDeniedException, InternalError, BadRequest, Conflict ) +from . import constants + try: from modoboa.lib.ldap_utils import LDAPAuthBackend @@ -60,6 +62,13 @@ class User(PermissionsMixin): ugettext_lazy('last login'), default=timezone.now ) + language = models.CharField( + max_length=10, default="en", choices=constants.LANGUAGES, + help_text=ugettext_lazy( + "Prefered language to display pages." + ) + ) + objects = UserManager() USERNAME_FIELD = 'username' diff --git a/modoboa/core/templates/core/user_preferences.html b/modoboa/core/templates/core/user_preferences.html index ef073e653..8bd449e74 100644 --- a/modoboa/core/templates/core/user_preferences.html +++ b/modoboa/core/templates/core/user_preferences.html @@ -1,9 +1,16 @@ {% load i18n %}{% load url from future %}