From 24bd2aa53c9b1f23d2a7e49d88b7a839c6919918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Wed, 24 Aug 2022 17:56:59 +0200 Subject: [PATCH] Add migrations md to html --- ram/consist/migrations/0006_md_to_html.py | 34 ++++++++++++++++++++ ram/portal/migrations/0012_md_to_html.py | 38 +++++++++++++++++++++++ ram/roster/migrations/0011_md_to_html.py | 34 ++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 ram/consist/migrations/0006_md_to_html.py create mode 100644 ram/portal/migrations/0012_md_to_html.py create mode 100644 ram/roster/migrations/0011_md_to_html.py diff --git a/ram/consist/migrations/0006_md_to_html.py b/ram/consist/migrations/0006_md_to_html.py new file mode 100644 index 0000000..8de0def --- /dev/null +++ b/ram/consist/migrations/0006_md_to_html.py @@ -0,0 +1,34 @@ +# Generated by Django 4.1 on 2022-08-24 15:30 + +import markdown +from django.db import migrations + + +def md_to_html(apps, schema_editor): + fields = { + 'Consist': ['notes'], + } + + for m in fields.items(): + model = apps.get_model('consist', m[0]) + + for row in model.objects.all(): + for field in m[1]: + field = getattr(row, field) + field = markdown.markdown(field) + + row.save(update_fields=m[1]) + + +class Migration(migrations.Migration): + + dependencies = [ + ("consist", "0005_alter_consist_notes"), + ] + + operations = [ + migrations.RunPython( + md_to_html, + reverse_code=migrations.RunPython.noop + ), + ] diff --git a/ram/portal/migrations/0012_md_to_html.py b/ram/portal/migrations/0012_md_to_html.py new file mode 100644 index 0000000..2e80f79 --- /dev/null +++ b/ram/portal/migrations/0012_md_to_html.py @@ -0,0 +1,38 @@ +# Generated by Django 4.1 on 2022-08-24 15:00 + +import markdown +from django.db import migrations + + +def md_to_html(apps, schema_editor): + fields = { + 'SiteConfiguration': ['about', 'footer', 'footer_extended'], + 'Flatpage': ['content'] + } + + for m in fields.items(): + model = apps.get_model('portal', m[0]) + + for row in model.objects.all(): + for field in m[1]: + field = getattr(row, field) + field = markdown.markdown(field) + + row.save(update_fields=m[1]) + + +class Migration(migrations.Migration): + + dependencies = [ + ( + "portal", + "0011_alter_flatpage_content_alter_siteconfiguration_about_and_more", + ), + ] + + operations = [ + migrations.RunPython( + md_to_html, + reverse_code=migrations.RunPython.noop + ), + ] diff --git a/ram/roster/migrations/0011_md_to_html.py b/ram/roster/migrations/0011_md_to_html.py new file mode 100644 index 0000000..00ec4ad --- /dev/null +++ b/ram/roster/migrations/0011_md_to_html.py @@ -0,0 +1,34 @@ +# Generated by Django 4.1 on 2022-08-24 15:30 + +import markdown +from django.db import migrations + + +def md_to_html(apps, schema_editor): + fields = { + 'RollingStock': ['notes'], + } + + for m in fields.items(): + model = apps.get_model('roster', m[0]) + + for row in model.objects.all(): + for field in m[1]: + field = getattr(row, field) + field = markdown.markdown(field) + + row.save(update_fields=m[1]) + + +class Migration(migrations.Migration): + + dependencies = [ + ("roster", "0010_alter_rollingstock_notes"), + ] + + operations = [ + migrations.RunPython( + md_to_html, + reverse_code=migrations.RunPython.noop + ), + ]