From be96f4058263c37f303d59e0d5a6e47013b55aa1 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 6 Oct 2012 16:43:10 +0530 Subject: [PATCH] modify doDir to import images in sequence if files have numbers in them --- urbstudio/urb/imports.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/urbstudio/urb/imports.py b/urbstudio/urb/imports.py index 4680260..f362230 100644 --- a/urbstudio/urb/imports.py +++ b/urbstudio/urb/imports.py @@ -1,6 +1,7 @@ from models import * from django.core.files import File from glob import glob +import re def importFile(filePath, project): f = File(open(filePath)) @@ -13,8 +14,11 @@ def importFile(filePath, project): return -def doDir(dirpath, project): - for f in glob("%s/*" % dirpath): +def doDir(dirpath, project, ext='JPG'): + fileList = glob("%s/*.%s" % (dirpath, ext,)) + sortedList = sorted(fileList, key=lambda f: int(re.findall(r'\d+', f)[0])) #if there's numbers in the filename, use them as indexes to order by. + print sortedList + for f in sortedList: importFile(f, project) print "all done" return