Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions geonode/people/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.utils.translation import gettext_lazy as _
from django.conf import settings

from geonode.people.utils import get_profile_language_choices

# Ported in from django-registration
attrs_dict = {"class": "required"}
Expand Down Expand Up @@ -52,7 +53,7 @@ class ProfileForm(forms.ModelForm):

language = forms.ChoiceField(
label=_("Language"),
choices=settings.PROFILE_LANGUAGE_CHOICES,
choices=get_profile_language_choices,
)

class Meta:
Expand Down
4 changes: 0 additions & 4 deletions geonode/people/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,10 +1361,6 @@ def test_authenticated_user_language_switch_updates_session_and_db(self):
("en-us", "English"),
("it-it", "Italiano"),
),
PROFILE_LANGUAGE_CHOICES=(
("en", "English"),
("it", "Italiano"),
),
)
def test_authenticated_user_language_switch_stores_profile_code_from_runtime_code(self):
user = get_user_model().objects.get(username="bobby")
Expand Down
8 changes: 8 additions & 0 deletions geonode/people/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,11 @@ def runtime_to_profile_lang(lang):
return None

return lang.lower().split("-")[0]


def get_profile_language_choices():
"""
Build the list of DB-based (2-char) language choices from the currently
configured settings.LANGUAGES
"""
return tuple({code.split("-")[0].lower(): label for code, label in settings.LANGUAGES}.items())
4 changes: 2 additions & 2 deletions geonode/people/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from geonode.tasks.tasks import send_email
from geonode.people.forms import ProfileForm
from geonode.people.utils import get_available_users, runtime_to_profile_lang
from geonode.people.utils import get_available_users, get_profile_language_choices, runtime_to_profile_lang
from geonode.base.auth import get_or_create_token
from geonode.people.forms import ForgotUsernameForm
from geonode.base.views import user_and_group_permission
Expand Down Expand Up @@ -178,7 +178,7 @@ def set_session_language(request):
raw_lang = request.POST.get("language")
profile_lang = runtime_to_profile_lang(raw_lang)

if profile_lang in {code for code, _label in settings.PROFILE_LANGUAGE_CHOICES}:
if profile_lang in {code for code, _label in get_profile_language_choices()}:
request.session[SESSION_LANG_KEY] = profile_lang

is_read_only = Configuration.load().read_only
Expand Down
3 changes: 0 additions & 3 deletions geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,9 +1436,6 @@ def get_geonode_catalogue_service():
else:
LANGUAGES = MAPSTORE_DEFAULT_LANGUAGES

# This setting includes supported Maptstore language choices in a DB-based format
PROFILE_LANGUAGE_CHOICES = tuple((code.split("-")[0].lower(), label) for code, label in LANGUAGES)

# The default mapstore client compiles the translations json files in the /static/mapstore directory
# gn-translations are the custom translations for the client and ms-translations are the translations from the core framework
MAPSTORE_TRANSLATIONS_PATH = os.environ.get(
Expand Down
Loading