import command method string
authordurandn
Fri, 16 Dec 2016 12:45:48 +0100
changeset 286 118756839a8a
parent 285 aa0f3e186d29
child 287 959cbaad2076
import command method string
src/iconolab/management/commands/importimages.py
--- a/src/iconolab/management/commands/importimages.py	Fri Dec 16 12:00:48 2016 +0100
+++ b/src/iconolab/management/commands/importimages.py	Fri Dec 16 12:45:48 2016 +0100
@@ -85,6 +85,24 @@
             help='regexp suffix to properly parse image names with info from csv. The pattern should describe the part after the filename identifier string, default is [\.\-_].*'
         )
     def handle(self, *args, **options):
+        """
+            Step-by-step for import:
+            
+            1) Argument checks for file existence and database state to check that everything can proceed without issue before reading the files
+            1) We import data from csv in a 'pivot' list of dicts 'cleaned_row_data' with the following logic:
+                * in the settings, there is value "IMPORT_FIELDS_DICT" that is a dict where each key is an identifier for the metadatas 
+                to which we associate a list of column header that will identified as that metadata
+                * The cleaned_row_data list will associate the identifier with the actual value for its related column 
+            2) Once we have cleaned_row_data, we filter out rows that don't have any associated image into a 'filtered_row_data' list, and add a key "SRC_IMG_FILES" that contains the list of images associated
+            to each row for the filtered data. 
+            3) At this point we have a list of all the items that will be created into the database and the related images to import, so we create the collection object if necessary
+            4) For each item:
+                We create the object in the database
+                * Metadatas are extracted from the filtered_csv_data using the pivot identifiers from settings.IMPORT_FIELD_DICT
+                We copy/convert the image into the MEDIA_ROOT/uploads/ dir
+                
+            Note: each unused row and each unused image in the import folder is kept track of in no_data_images, no_image_rows and duplicate_rows lists and logged at the end of the command.
+        """
         try:
             print('# Logging with logger '+logger.name)
             logger.debug('# Initializing command with args: %r', options)