From e9ef293cf71f5bf834e3a3ea73094347e6925eb2 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 19 Jul 2019 12:39:24 +0200 Subject: [PATCH] Added logo and font migrations --- .../0005_directories_and_permissions_2.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/openslides/mediafiles/migrations/0005_directories_and_permissions_2.py b/openslides/mediafiles/migrations/0005_directories_and_permissions_2.py index 71d70c0ca..6a05895a1 100644 --- a/openslides/mediafiles/migrations/0005_directories_and_permissions_2.py +++ b/openslides/mediafiles/migrations/0005_directories_and_permissions_2.py @@ -1,14 +1,39 @@ # Generated by Django 2.2.2 on 2019-06-28 06:09 import os.path +from typing import List from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType from django.db import migrations +def change_logo_and_font_configs(apps, schema_editor): + """ + All old paths with "/media/file/..." will be replaced with "/media/...". + """ + ConfigStore = apps.get_model("core", "ConfigStore") + + logo_font_keys: List[str] = [] + try: + logo_font_keys.extend(ConfigStore.objects.get(key="logos_available").value) + logo_font_keys.extend(ConfigStore.objects.get(key="fonts_available").value) + except ConfigStore.DoesNotExist: + pass + + for key in logo_font_keys: + config = ConfigStore.objects.get(key=key) + logo = config.value + path = logo.get("path") + if path and path.startswith("/media/file/"): + logo["path"] = path.replace("/media/file/", "/media/", 1) + config.value = logo + config.save() + + def copy_filename(apps, schema_editor): Mediafile = apps.get_model("mediafiles", "Mediafile") + for mediafile in Mediafile.objects.all(): filename = os.path.basename(mediafile.mediafile.name) mediafile.original_filename = filename @@ -41,6 +66,7 @@ class Migration(migrations.Migration): dependencies = [("mediafiles", "0004_directories_and_permissions_1")] operations = [ + migrations.RunPython(change_logo_and_font_configs), migrations.RunPython(copy_filename), migrations.RunPython(set_groups_and_delete_old_permissions), ]