Skip to content

Commit

Permalink
Handle case where locale gets completely deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
ayanaar committed Nov 25, 2023
1 parent 05e8dbd commit 4465127
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pontoon/contributors/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
HttpResponse,
HttpResponseBadRequest,
JsonResponse,
Http404,
)
from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone
Expand Down Expand Up @@ -311,23 +312,37 @@ def settings(request):
all_locales.insert(0, default_homepage_locale)

# Set default for custom homepage locale based on code
if profile.custom_homepage:
custom_homepage_locale = get_locale_or_redirect(profile.custom_homepage)
else:
try:
if profile.custom_homepage:
custom_homepage_locale = get_locale_or_redirect(profile.custom_homepage)
else:
custom_homepage_locale = default_homepage_locale
except Http404:
custom_homepage_locale = default_homepage_locale
messages.info(
request,
"Your previously selected custom homepage locale is no longer available. Reverted to default.",
)

# Similar logic for preferred source locale
default_preferred_source_locale = Locale(name="Default project locale", code="")
preferred_locales = list(Locale.objects.all())
preferred_locales.insert(0, default_preferred_source_locale)

# Set preferred source locale based on code
if profile.preferred_source_locale:
preferred_source_locale = get_locale_or_redirect(
profile.preferred_source_locale
)
else:
try:
if profile.preferred_source_locale:
preferred_source_locale = get_locale_or_redirect(
profile.preferred_source_locale
)
else:
preferred_source_locale = default_preferred_source_locale
except Http404:
preferred_source_locale = default_preferred_source_locale
messages.info(
request,
"Your previously selected preferred source locale is no longer available. Reverted to default.",
)

return render(
request,
Expand Down

0 comments on commit 4465127

Please sign in to comment.