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 --- .../migrations/0251_data_default_welcome.py | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ishtar_common/migrations/0251_data_default_welcome.py (limited to 'ishtar_common/migrations/0251_data_default_welcome.py') diff --git a/ishtar_common/migrations/0251_data_default_welcome.py b/ishtar_common/migrations/0251_data_default_welcome.py new file mode 100644 index 000000000..df1f10a5e --- /dev/null +++ b/ishtar_common/migrations/0251_data_default_welcome.py @@ -0,0 +1,39 @@ +# Generated by Django 2.2.24 on 2024-09-26 11:53 + +from django.conf import settings +from django.db import migrations +from django.template import Context, Template +from django.utils import translation + +from ishtar_common.utils_migrations import HOMEPAGE_DEFAULT, HOMEPAGE_TITLE + + +def default_welcome(apps, __): + IshtarSiteProfile = apps.get_model("ishtar_common", "IshtarSiteProfile") + old_language = translation.get_language() + translation.activate(settings.LANGUAGE_CODE) + homepage = Template(HOMEPAGE_DEFAULT).render(Context({}, use_l10n=True)) + title = str(HOMEPAGE_TITLE) + translation.activate(old_language) + for profile in IshtarSiteProfile.objects.all(): + changed = False + if not profile.homepage: + changed = True + profile.homepage = homepage + if not profile.homepage_title: + changed = True + profile.homepage_title = title + if changed: + profile.save() + + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0250_profile_homepage'), + ] + + operations = [ + migrations.RunPython(default_welcome) + ] -- cgit v1.2.3