From fba45498ad417cc65f53901d19e1b85e3f18e0bc Mon Sep 17 00:00:00 2001 From: rasarkar <105652044+rasarkar@users.noreply.github.com> Date: Fri, 10 May 2024 10:59:58 -0400 Subject: [PATCH] CONCD-765 Allow CMs to change Guide titles (Requires Migration) (#2373) * CONCD-765 Guide titles (requires migration) * CONCD-765 having guides point to simple pages, instead of vice versa --- .../migrations/0091_guide_simple_page.py | 24 +++++++++++++++ .../migrations/0092_auto_20240509_1522.py | 30 +++++++++++++++++++ concordia/models.py | 3 ++ concordia/templates/static-page.html | 10 +++---- concordia/views.py | 21 +++---------- 5 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 concordia/migrations/0091_guide_simple_page.py create mode 100644 concordia/migrations/0092_auto_20240509_1522.py diff --git a/concordia/migrations/0091_guide_simple_page.py b/concordia/migrations/0091_guide_simple_page.py new file mode 100644 index 000000000..5067fae31 --- /dev/null +++ b/concordia/migrations/0091_guide_simple_page.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.13 on 2024-05-09 19:21 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("concordia", "0090_auto_20240408_1334"), + ] + + operations = [ + migrations.AddField( + model_name="guide", + name="page", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="concordia.simplepage", + ), + ), + ] diff --git a/concordia/migrations/0092_auto_20240509_1522.py b/concordia/migrations/0092_auto_20240509_1522.py new file mode 100644 index 000000000..c0c93a590 --- /dev/null +++ b/concordia/migrations/0092_auto_20240509_1522.py @@ -0,0 +1,30 @@ +# Generated by Django 4.2.13 on 2024-05-09 19:22 + +from django.db import migrations + + +def set_simplepages(apps, schema_editor): + SimplePage = apps.get_model("concordia", "SimplePage") + Guide = apps.get_model("concordia", "Guide") + for guide in Guide.objects.all(): + page = SimplePage.objects.get(title=guide.title) + guide.page = page + guide.save() + + +def backwards(apps, schema_editor): + Guide = apps.get_model("concordia", "Guide") + for guide in Guide.objects.all(): + guide.page = None + guide.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("concordia", "0091_guide_simple_page"), + ] + + operations = [ + migrations.RunPython(set_simplepages, backwards), + ] diff --git a/concordia/models.py b/concordia/models.py index fca7c0811..ca93a1767 100644 --- a/concordia/models.py +++ b/concordia/models.py @@ -983,6 +983,9 @@ class Meta: class Guide(models.Model): title = models.CharField(max_length=80) + page = models.ForeignKey( + SimplePage, on_delete=models.SET_NULL, blank=True, null=True + ) body = models.TextField(blank=True) order = models.IntegerField(default=1) link_text = models.CharField(max_length=80, blank=True, null=True) diff --git a/concordia/templates/static-page.html b/concordia/templates/static-page.html index 6e2fa8aca..e5b03b625 100644 --- a/concordia/templates/static-page.html +++ b/concordia/templates/static-page.html @@ -24,12 +24,10 @@