From 8e044f2d438578405321d0a4594b8e5048864cf6 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 22 Jan 2014 14:56:19 +0100 Subject: [PATCH] fix path for import without copy --- .../commands/telemeta-import-items-without-copy.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/telemeta/management/commands/telemeta-import-items-without-copy.py b/telemeta/management/commands/telemeta-import-items-without-copy.py index d11c28e2..b82d945b 100644 --- a/telemeta/management/commands/telemeta-import-items-without-copy.py +++ b/telemeta/management/commands/telemeta-import-items-without-copy.py @@ -13,9 +13,10 @@ class Command(BaseCommand): def handle(self, *args, **options): collection_code = args[-2] - media_dir = args[-1] - - if not settings.MEDIA_ROOT in os.path.abspath(media_dir): + import_dir = os.path.abspath(args[-1]) + media_dir = os.path.normpath(settings.MEDIA_ROOT) + + if not media_dir in import_dir: sys.exit('This directory is not in the MEDIA_ROOT directory') collections = MediaCollection.objects.filter(code=collection_code) @@ -28,11 +29,13 @@ class Command(BaseCommand): collection = collections[0] print 'using collection: ' + collection.code - for root, dirs, files in os.walk(media_dir): + for root, dirs, files in os.walk(import_dir): for filename in files: path = root + os.sep + filename + path = path[len(media_dir)+1:] name, ext = os.path.splitext(filename) - items = MediaItem.objects.filter(code=name) + name = collection_code + '_' + name + items = MediaItem.objects.filter(collection=collection, code=name) if not items: item = MediaItem(collection=collection, code=name) item.title = name -- 2.39.5