From 050f1de4786832d1c11f68a8e3eac041e9030801 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Mon, 3 Sep 2018 10:26:38 +0100 Subject: [PATCH] Handle the file path for files with _0 and non standard paths --- opentech/apply/funds/management/commands/migration_base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/opentech/apply/funds/management/commands/migration_base.py b/opentech/apply/funds/management/commands/migration_base.py index f68846698..77c2b73cc 100644 --- a/opentech/apply/funds/management/commands/migration_base.py +++ b/opentech/apply/funds/management/commands/migration_base.py @@ -1,5 +1,7 @@ import argparse import json +import os +from urllib.parse import urlsplit from datetime import datetime, timezone @@ -143,7 +145,6 @@ class MigrateCommand(BaseCommand): self.stdout.write(f"Processed \"{node['title']}\" ({node['nid']})") except IntegrityError: self.stdout.write(f"*** Skipped \"{node['title']}\" ({node['nid']}) due to IntegrityError") - pass def get_user(self, uid): try: @@ -291,7 +292,8 @@ class MigrateCommand(BaseCommand): files = [] for file_data in value: - file_path = 'files/private/application_upload/' + file_data['filename'] + parts = urlsplit(file_data['uri']) + file_path = os.path.join('files', 'private', parts.netloc, *parts.path.split('/')) saved_file = migration_storage.open(file_path) saved_file.name = file_data['filename'] files.append(saved_file) -- GitLab