# HG changeset patch # User durandn # Date 1480687674 -3600 # Node ID 5e719c9c87de6503a708bff1dfe7f4097fa59be6 # Parent ffe9b08ca52fe800263e063e848bd43c7656eab0 import adjustement to handle duplicate rows diff -r ffe9b08ca52f -r 5e719c9c87de src/iconolab/management/commands/importimages.py --- 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: