From a44bb4131dd191b4ef5be4e1403fd18bb4987b55 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 26 Sep 2024 14:31:54 +0200 Subject: 🩹 Welcome page: simplify and init Welcome fields management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/views.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'ishtar_common/views.py') diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 2772bd44f..5b675eb52 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -53,7 +53,9 @@ from django.http import ( JsonResponse, ) from django.shortcuts import redirect, render, get_object_or_404 +from django.template import Context, Template from django.urls import reverse, NoReverseMatch +from django.utils import translation from django.utils.decorators import method_decorator from django.utils.translation import ugettext, ugettext_lazy as _ from django.views.generic import ListView, TemplateView, View @@ -73,6 +75,7 @@ from ishtar_common.data_importer import ImporterError from ishtar_common.forms import FinalForm, FinalDeleteForm, reverse_lazy from ishtar_common.models import get_current_profile from ishtar_common.templatetags.link_to_window import simple_link_to_window +from ishtar_common.utils_migrations import HOMEPAGE_DEFAULT, HOMEPAGE_TITLE from ishtar_common.utils import ( clean_session_cache, CSV_OPTIONS, @@ -182,8 +185,9 @@ def index(request): Main page """ profile = get_current_profile() + welcome_title = profile.homepage_title or str(HOMEPAGE_TITLE) dct = {"warnings": [], "extra_form_modals": wizards.EXTRA_FORM_MODALS, - "welcome_title": profile.homepage_title} + "welcome_title": welcome_title} if settings.PROJECT_SLUG == "default": dct["warnings"].append( _( @@ -204,11 +208,18 @@ def index(request): dct["display_random_image"] = True dct["random_image"] = get_random_item_image_link(request) - if hasattr(profile, "homepage") and profile.homepage: + if profile.homepage: dct["homepage"] = markdown(profile.homepage) # remove old hardcoded "{random_image}" from custom templates if "{random_image}" in dct["homepage"]: dct["homepage"] = dct["homepage"].replace("{random_image}", "") + else: + old_language = translation.get_language() + translation.activate(settings.LANGUAGE_CODE) + dct["homepage"] = Template(HOMEPAGE_DEFAULT).render(Context({}, use_l10n=True)) + translation.activate(old_language) + + dct["homepage"] = dct["homepage"].replace("ISHTAR_DOCUMENT_VERSION", settings.ISHTAR_DOCUMENT_VERSION) display_statistics = profile.homepage_statistics_available and ( authenticated or profile.homepage_statistics_available_offline -- cgit v1.2.3