Allows for batch import of django model data via uploaded Microsoft Excel files, saved as XLS files (Excel Binary file format). Of course, you can also use OpenOffice or CSV files, but you will have to convert them to the XLS format beforehand.
Some screenshots of SynCoor used in a document management application are available here.
This experimental forks uses "class-based views" to provide more flexibility
BATCHIMPORT_TEMPDIR
: Directory when temporary XLS data will be stored (default:/tmp/
)
-
ImportUploadView
: FormView with fieldsmodel_to_import
andimport_file
- Options :
template_name
: template used to render the view (default:batchimport/upload.html
)options_url
: name of the URL pattern pointing to the ImportOptionsView (default:batchimport_options
)
- Options :
-
ImportOptionsView
: FormView that asks the user information about the data processing.- Options :
template_name
: template used to render the view (default:batchimport/options.html
)processing_template_name
: template displayed while batchimport is processing the data (default:batchimport/processing.html
)upload_url
: name of the URL pattern pointing to the ImportUploadFile, in case we need to go back (default:batchimport_upload
)
- Options :
-
ImportRunView
: TemplateView that runs the import and displays the rsults- Options :
template_name
: template used to render the view (default:batchimport/run.html
)upload_url
: name of the URL pattern pointing to the ImportUploadFile, in case we need to go back (default:batchimport_upload
)
- Context :
start_row
: first row to be importedend_row
: last row to be importedrow_count
: row countprocessed_count
: processed rows countimported_count
: imported (created in database) objects countupdated_count
: updated objects countcombined_messages
: combined import and update resultsimport_messages
: imports resultsupdate_messages
: updates resultserror_messages
: errors
- Options :
The context variables listed above ending in _messages
have a specific format. combined_messages
, import_messages
and update_messages
are lists of dicts with the following keys :
description
: Description of the event ("Updated row 45.")object_id
: Database ID of the object created/updated
error_messages
is made of a list of dicts with the following keys :
name
: Name of the errorcritical
: Boolean indicating if the error triggers a global failure of the importdescription
: Description of the errorinfo
: Additional info (list of strings, each string represents a line)
django-batchimport uses the following session variables to store data between its views n:
batchimport_file_name
(set byImportUploadView
)batchimport_model
(set byImportUploadView
)batchimport_options
(set byImportOptionsView
)batchimport_info
(set byImportOptionsView
)
These variables are erased at the end of the import operation (in ImportRunView.run_import()
)
WARNING: Because the batchimport_info
is a ModelImportInfo
object (django-batchimport specific class), and ModelImportInfo
is not JSON-serializable, it is not possible to use JSON serialization to store your session data.
pip install git+git://github.com/pstch/django-batchimport.git
Or clone http://github.com/pstch/django-batchimport.git
and install package yourself using setup.py
.
Add batchimport
to INSTALLED_APPS
in settings.py
If you want to use django-batchimport's own URL config :
Add the following URL pattern in urls.py
:
(r'^batchimport/', include('batchimport.urls')),
But you can also subclass the three views ImportUploadView
, ImportOptionsView
and ImportRunView
in order to set your own settings and also your own URL patterns.
Just remember that whenever you change a URL pattern's name, you have to change it accordingly in the upload_url
and options_url
view attributes, and in the templates.