You have installed the test django-csvimport 8 | application. Click on the admin 9 | to try it
10 |NB: you must edit csvimport.settings to add
11 | MIGRATION_MODULES={"csvimport": "csvimport.tests.migrations"}
12 | Then run:
13 | django-admin.py migrate --settings=csvimport.settings
14 | to create the test models.
15 |
Click on csvimport in the admin
16 |Try importing data via the test csv files in 17 | django-csvimport/csvimport/tests/fixtures folder
18 |Click on Add csvimport
19 |For example select Models name: tests.Country and upload the countries.csv file
20 | """ 21 | ) 22 | -------------------------------------------------------------------------------- /csvimport/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for foobar project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "csvimport.settings") 13 | 14 | from django.core.wsgi import get_wsgi_application 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /docs/HISTORY.txt: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | Contributors listed as [github.com username] where they are on github 5 | 6 | 3.2 - Use dateparser for import - 26 Dec 2023 7 | --------------------------------------------------------- 8 | 9 | #. Use dateparser for importing a much wider range of mixed date formats without specifying a format 10 | #. Remove old tz monkeypatch 11 | 12 | 3.1 - Add messytables for django 5 - 23 Dec 2023 13 | ------------------------------------------------ 14 | 15 | #. Use dateparser rather than python-dateutil and add to setup.py dependencies 16 | 17 | 3.0 - Add messytables for django 5 - 23 Dec 2023 18 | ------------------------------------------------ 19 | 20 | #. Upgrade to Django 5, hence Python 3.12 21 | #. Add csvimport/messytables with two files to provide functionality used from OKN messytables, since the whole package is no longer maintained for Python 3.12 [OKN] 22 | #. Autoformat the code with black 23 | 24 | 2.17 - Fix for django 4 - 2 Jan 2023 25 | ------------------------------------ 26 | 27 | #. Fix incompatible methods for django 4 28 | #. Add a test for single row CSV and fix issue of trailing line returns 29 | #. Minor issue PRs [edouard-gv] 30 | 31 | 2.16 - Fix and add tests - 28 June 2020 32 | --------------------------------------- 33 | 34 | #. Move test fixture migrations to separate migration folder picked up by custom testrunner 35 | #. Add regression tests for all reported issues 36 | #. Add admin UI tests 37 | #. Enable and fix all existing tests 38 | #. Use regex match group for failover CSV splitter 39 | 40 | 2.15 - Fix compatiblity issue for Django 3 - 27 April 2020 41 | ---------------------------------------------------------- 42 | 43 | 2.13 - Fix issue with inspectcsv for different header and data line number of cols - 26th Sept 2019 44 | --------------------------------------------------------------------------------------------------- 45 | 46 | 2.12 - Fix for latest django required on_delete and duplicated log msgs - 24 April 2019 47 | --------------------------------------------------------------------------------------- 48 | 49 | 2.11 - Fix command line summary messages - 14 July 2017 50 | ------------------------------------------------------- 51 | 52 | 2.10 - Bug with models var not set if not bulk import - 6 July 2017 53 | -------------------------------------------------------------------- 54 | 55 | 2.9 - Fix for using foreign keys from other apps - 4 July 2017 56 | -------------------------------------------------------------- 57 | 58 | #. Handle boolean types actually being ints for sqlite 59 | #. Allow dots in --mappings so app labels of foreign keys can be set by the user, since model lookup may assume wrong label. 60 | 61 | 2.8 - Minor fixes - 19 June 2017 62 | -------------------------------- 63 | 64 | #. Force datetimes to local timezone to prevent warning on insert 65 | #. Rebuild initial migrations file 66 | #. Add option to do bulk create with --bulk to speed up import 67 | 68 | 2.7 - Merge in pull requests for minor fixes and test with Django 1.11 - 30 May 2017 69 | ------------------------------------------------------------------------------------ 70 | 71 | #. Fix uninitiated variable bug if type not detected 72 | #. Fix command line arg usage for Django 1.10 or 1.11 and make it backwards compatible down to 1.7 73 | #. For multiple django version compatibility code try excepts make sure new syntax is first to avoid deprecation warnings 74 | #. Add test shell script to make it easy to run test suite and a command line test 75 | #. Report back matched and unmatched cols in CSV rather than just showing list of all of them 76 | #. Allow clean=false option to not fix numeric values to match allowed range 77 | #. Use atomic to wrap row inserts so we can still report count of inserts Ok after a transactional exception 78 | 79 | 2.5 - Merge in various pull requests and test with Django 1.7 to 1.10 - 15 Nov 2016 80 | ----------------------------------------------------------------------------------- 81 | 82 | #. Fix for all recent versions of Django and Python 83 | #. Add in delimiter option eg. for tab separated values 84 | #. Add migrations 85 | #. Make importcsv parsing more tolerant of unparsable rows in CSV 86 | 87 | 2.4 - Fix app config path so that management commands are found - 11 Nov 2014 88 | ----------------------------------------------------------------------------- 89 | 90 | #. Fix log print for commands 91 | 92 | 2.3 - Make compatible with Python 3 - 29 October 2014 93 | ----------------------------------------------------- 94 | 95 | 2.2 - Move to core appconfig usage - 28 October 2014 96 | ---------------------------------------------------- 97 | 98 | #. Add appconfig path to cater for module install test running 99 | #. Check for SMALLINT_DBS including sqlite - since can fail big int imports 100 | 101 | 2.1 - Fix for django 1.7 - 27 October 2014 102 | ------------------------------------------ 103 | 104 | 2.0 - Added model creation and datetime clean up - 29th Sept 2014 105 | ----------------------------------------------------------------- 106 | 107 | #. Generate django model files based on CSV data type sniffing with messytables 108 | #. Use flag to generate model code eg. --model=create_new_model.modelname and add test 109 | #. Use the settings date formats and add clean up for them 110 | #. Factor out type clean up method for data values 111 | #. Allow defaults to be passed as a command line argument 112 | #. Use --mappings=none for CSV created models with no column name row 113 | #. Handle badly encoded files as raw 114 | #. Set date limit in case of strftime bug for pre-1900 dates 115 | 116 | [edcrewe] 117 | 118 | 1.1 - Added mappings and defaults tests - 18 March 2014 119 | ------------------------------------------------------- 120 | 121 | #. Allow mapping format to be simple header row style 122 | #. Refactored heading parsing and added tests for optional args 123 | 124 | [edcrewe] 125 | 126 | 1.0 - Added signals and code cleanup - 29th January 2013 127 | -------------------------------------------------------- 128 | 129 | #. Fixed number overflow test and tested with django 1.5.1 [edcrewe] 130 | #. Added signals to the app, to allow the model to custom format a row. 131 | #. added appconf to allow the app to be more customizable - eg. select models for import. 132 | #. Removed except all and return database errors. 133 | 134 | [cwood] 135 | 136 | 0.9 - Missed import of re for change to display of error log - 9th Dec 2012 137 | --------------------------------------------------------------------------- 138 | 139 | #. Import re in csvimport/models.py [blorenz] 140 | 141 | 0.8 - Tidy up logging and Boolean handling - 9th Dec 2012 142 | --------------------------------------------------------- 143 | 144 | #. Fix display of error log so there are newlines for each entry [smeyfroi] 145 | #. Log processed rows to the csvimport.management.commands.csvimport logger [smeyfroi] 146 | #. Fix for boolean data [smeyfroi] 147 | #. Add setting for using standard logging machinery for Admin UI log lines [edcrewe] 148 | #. Add test to check creation and content of csvimport log file [edcrewe] 149 | 150 | 0.7 - Fixes and merge in changes for running up the test app - 24th Nov 2012 151 | ---------------------------------------------------------------------------- 152 | 153 | #. Merge in changes for 1.4 templates in settings [elena] 154 | #. Merge in doc changes [elena, valhallasw] 155 | #. Fix bug with columns that are floats [imposeren] 156 | #. Fix imports via the admin not having charset encoding argument [edcrewe] 157 | 158 | 0.6 - Handle text not number or special float to integer - 7th March 2012 159 | ------------------------------------------------------------------------- 160 | 161 | #. Handle numeric columns with text in - zero if not nan or inf 162 | 163 | [edcrewe] 164 | 165 | 0.5 - Add command line encoding option and error return - 6th March 2012 166 | ------------------------------------------------------------------------ 167 | 168 | #. Make sure command line usage returns errors and warnings 169 | #. Add the option to force --charset=utf-8 for example rather than chardet 170 | #. Add numeric type handling for empty fields or other issues plus tests 171 | 172 | [Tessa Alexander, edcrewe] 173 | 174 | 0.4 - Add settings to allow demo site install from tests - 4th October 2011 175 | --------------------------------------------------------------------------- 176 | 177 | #. Add demo countries.csv file 178 | #. Add MEDIA_ROOT for file uploads 179 | 180 | [edcrewe] 181 | 182 | 0.3 - Fix issue with adding in admin - 25th Sept 2011 183 | ----------------------------------------------------- 184 | 185 | #. Fix empty mapping submitted 186 | #. Remove non-generic filename country processing code 187 | #. Use get_models to populate drop down for admin import form 188 | #. Add upload message about whether mapping is from CSV header row 189 | #. Ensure header row only used if mapping is not supplied. 190 | 191 | [edcrewe] 192 | 193 | 0.2 - Initial beta release version - 29th July 2011 194 | --------------------------------------------------- 195 | 196 | #. Build it as a django-csvimport egg 197 | #. Create csvimport management command 198 | #. Improve character set detection and unicode handling 199 | #. Add admin csvimport model to upload CSV files with logging of import 200 | #. Use file upload save to trigger csvimport command 201 | #. Autodetect column mappings by matching model fields and CSV header text 202 | #. Add a deduplicate feature 203 | #. Start to add test suite with data / app for HELIOS cross agency supply chain 204 | data sharing http://www.helios-foundation.org/cbha-project/index_html 205 | 206 | [edcrewe] 207 | 208 | 0.1 - Unreleased 209 | ---------------- 210 | 211 | #. Use django snippet as starting point 212 | http://djangosnippets.org/snippets/633/ 213 | 214 | [Jonathan Holst] 215 | -------------------------------------------------------------------------------- /docs/test_script.sh: -------------------------------------------------------------------------------- 1 | echo "Test shell script for running the shell command to import a CSV file and then check it worked by using commandline sqlite3" 2 | echo "Run from the root of your django install" 3 | export root=src/django-csvimport 4 | # export root=lib/python2.7/site-packages 5 | rm $root/db.sqlite3 6 | bin/django-admin.py migrate --settings='csvimport.settings' 7 | bin/django-admin.py importcsv --settings='csvimport.settings' --model='csvimport.Country' $root/csvimport/tests/fixtures/countries.csv 8 | sqlite3 $root/db.sqlite3 "select * from csvtests_country" 9 | echo "Run test suite" 10 | bin/django-admin.py test --settings='csvimport.settings' csvimport.tests 11 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [egg_info] 2 | tag_build = 3 | tag_svn_revision = false 4 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | try: 4 | from setuptools import setup 5 | except ImportError: 6 | from distutils.core import setup 7 | 8 | version = "3.2" 9 | 10 | with open("README.rst", "r") as fp: 11 | csvimport_description = fp.read() + "\n" 12 | for fname in ("HISTORY.txt",): 13 | with open(os.path.join("docs", fname), "r") as fp: 14 | csvimport_description += fp.read() + "\n" 15 | 16 | setup( 17 | name="django-csvimport", 18 | version=version, 19 | description="Import CSV files to django models", 20 | long_description_content_type="text/x-rst", 21 | long_description=csvimport_description, 22 | # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers 23 | classifiers=[ 24 | "Programming Language :: Python", 25 | "Topic :: Software Development :: Libraries :: Python Modules", 26 | "Development Status :: 5 - Production/Stable", 27 | "Framework :: Django", 28 | "Programming Language :: Python :: 2.6", 29 | "Programming Language :: Python :: 2.7", 30 | "Programming Language :: Python :: 3.3", 31 | "Programming Language :: Python :: 3.4", 32 | "Programming Language :: Python :: 3.5", 33 | "Programming Language :: Python :: 3.6", 34 | "Programming Language :: Python :: 3.7", 35 | "Programming Language :: Python :: 3.8", 36 | "Programming Language :: Python :: 3.9", 37 | "Programming Language :: Python :: 3.12", 38 | "License :: OSI Approved :: Apache Software License", 39 | ], 40 | keywords="CVS import django fixture", 41 | author="Ed Crewe", 42 | author_email="edmundcrewe@gmail.com", 43 | url="https://github.com/edcrewe/django-csvimport", 44 | license="Apache", 45 | packages=["csvimport"], 46 | include_package_data=True, 47 | namespace_packages=["csvimport"], 48 | # this line always breaks install? 49 | # package_data = {'csvimport': ['*.csv', '*.rst']}, 50 | zip_safe=False, 51 | install_requires=["django>=2.2.5", "chardet", "dateparser"], 52 | entry_points=""" 53 | # -*- Entry points: -*- 54 | """, 55 | ) 56 | --------------------------------------------------------------------------------