--- a/src/iconolab/management/commands/importimages.py Wed Nov 30 15:58:38 2016 +0100
+++ b/src/iconolab/management/commands/importimages.py Fri Dec 02 15:07:54 2016 +0100
@@ -150,6 +150,7 @@
print('# Extracting data from csv file and storing it in standardized format')
# We store data using the Jocondelab keys, as defined in settings.IMPORT_FIELDS_DICT
cleaned_csv_data=[]
+ duplicate_rows=[]
for row in csvreader:
cleaned_row_data = {}
for key in settings.IMPORT_FIELDS_DICT.keys():
@@ -162,7 +163,11 @@
else:
cleaned_row_data[key] = row[row_key]
break
- cleaned_csv_data.append(cleaned_row_data)
+ if cleaned_row_data[options.get('img_filename_identifier')] in [row[options.get('img_filename_identifier')] for row in cleaned_csv_data]:
+ print("## We already have "+options.get('img_filename_identifier')+" value "+cleaned_row_data[options.get('img_filename_identifier')]+" in the data to import, ignoring duplicate line")
+ duplicate_rows.append(cleaned_row_data)
+ else:
+ cleaned_csv_data.append(cleaned_row_data)
# Listing image files in csv directory
image_list = [
f for f in os.listdir(source_dir)
@@ -357,6 +362,15 @@
else:
print('## Each row found at least one corresponding image!')
logger.debug('### Each row found at least one corresponding image!')
+ print('# Duplicate rows in csv')
+ logger.debug('## Checking duplicate rows in csv')
+ if duplicate_rows:
+ for item in no_image_rows:
+ logger.debug('### %r: %r', options.get('img_filename_identifier'), item[options.get('img_filename_identifier')])
+ print('## '+options.get('img_filename_identifier')+': '+item[options.get('img_filename_identifier')])
+ else:
+ print('## Each row found at least one corresponding image!')
+ logger.debug('### Each row found at least one corresponding image!')
except FileNotFoundError:
print('!!! File '+options.get('csv_path')+' does not exist. !!!')
except ValueError as e: