summaryrefslogtreecommitdiff
path: root/ishtar_common/migrations/0251_data_default_welcome.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-26 14:31:54 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-26 17:48:33 +0200
commita44bb4131dd191b4ef5be4e1403fd18bb4987b55 (patch)
tree94aed38b0e4b888cbd299e38a633444d219220ea /ishtar_common/migrations/0251_data_default_welcome.py
parentf18ffffb54004411ed8cb981aef097d9f1051ead (diff)
downloadIshtar-a44bb4131dd191b4ef5be4e1403fd18bb4987b55.tar.bz2
Ishtar-a44bb4131dd191b4ef5be4e1403fd18bb4987b55.zip
🩹 Welcome page: simplify and init Welcome fields management
Diffstat (limited to 'ishtar_common/migrations/0251_data_default_welcome.py')
-rw-r--r--ishtar_common/migrations/0251_data_default_welcome.py39
1 files changed, 39 insertions, 0 deletions
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)
+ ]