From ca91572ab477fd8a074b32ca827980e7094e930e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 1 Apr 2020 00:32:51 +0200 Subject: [PATCH] add data migration to localize files with external URLs --- .../0008_localize_files_20200401_1221.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 sdbs_pile/pile/migrations/0008_localize_files_20200401_1221.py diff --git a/sdbs_pile/pile/migrations/0008_localize_files_20200401_1221.py b/sdbs_pile/pile/migrations/0008_localize_files_20200401_1221.py new file mode 100644 index 0000000..7570a4b --- /dev/null +++ b/sdbs_pile/pile/migrations/0008_localize_files_20200401_1221.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.4 on 2020-04-01 10:21 +from urllib.parse import unquote + +from django.db import migrations + + +# noinspection PyPep8Naming +def localize_file(apps, schema_editor): + Document = apps.get_model('pile', 'Document') + for document in Document.objects.all(): + if not bool(document.file) and "pile.sdbs.cz" in document.external_url: + document.file.name = unquote(document.external_url.split("/")[-1]) + document.save() + + +class Migration(migrations.Migration): + dependencies = [ + ('pile', '0007_document_status'), + ] + + operations = [ + migrations.RunPython(localize_file) + ]