Changes between Version 11 and Version 12 of S3/DataImportCLI
- Timestamp:
- 06/13/14 11:55:49 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3/DataImportCLI
v11 v12 6 6 7 7 Start the web2py CLI with the Eden data model environment: 8 {{{ 8 {{{#!python 9 9 python web2py.py -S eden -M 10 10 }}} 11 11 12 12 Override authorization: 13 {{{ 13 {{{#!python 14 14 auth.override = True 15 15 }}} 16 16 17 17 Define the target resource: 18 {{{ 18 {{{#!python 19 19 resource = s3db.resource("project_activity") 20 20 }}} 21 21 22 22 Import data: 23 {{{ 23 {{{#!python 24 24 success = resource.import_xml(open("filename.csv", "rb"), # CSV format requires file handle, XML accepts filename 25 25 format="csv", # "xml", "json" or "csv" … … 31 31 32 32 See errors (error message and error tree are returned in any case, even with ignore_errors=True): 33 {{{ 33 {{{#!python 34 34 print success # prints a JSON message with the error message and the JSONified error tree 35 35 print resource.error # prints the error message … … 39 39 40 40 Do not forget to commit the import (if you want to keep it): 41 {{{ 41 {{{#!python 42 42 db.commit() 43 43 }}} 44 44 45 45 If you were only testing (e.g. to see validation errors), and now want to discard the import, you can either leave the shell without calling {{{db.commit()}}} - or you do an explicit: 46 {{{ 46 {{{#!python 47 47 db.rollback() 48 48 }}}