Changeset 4391
- Timestamp:
- 2 Jul 2009, 09:53:15 (15 years ago)
- Location:
- waeup/branches/ulif-rewrite/src/waeup
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/university/facultycontainer.txt
r4232 r4391 69 69 know before. 70 70 71 Importing from CSV files72 ------------------------73 74 We create a facultycontainer, which we want to populate with some CSV75 data afterwards:76 77 >>> from waeup.university.facultycontainer import FacultyContainer78 >>> mycontainer = FacultyContainer()79 80 Next, we create a CSV file we want to import:81 82 >>> open('myfaculties.csv', 'wb').write(83 ... """code,review_state,title,title_prefix84 ... AGR,static,Agriculture,faculty85 ... ART,static,Arts,faculty86 ... DEN,static,Dentistry,faculty87 ... """)88 89 We get a suitable importer by asking for a multi-adapter to90 our file and IWAeUPCSVExporter (see section above, the importexport91 module and the `waeup.csvfile` README for details):92 93 >>> from waeup.csvfile import getCSVFile94 >>> from waeup.interfaces import IWAeUPCSVImporter95 >>> from zope.component import getMultiAdapter96 >>> importer = getMultiAdapter((getCSVFile('myfaculties.csv'),97 ... mycontainer),98 ... IWAeUPCSVImporter)99 >>> importer100 <waeup.university.facultycontainer.FacultyCSVImporter object at 0x...>101 102 This importer complies with the IWAeUPCSVImporter interface:103 104 >>> from waeup.university.facultycontainer import FacultyCSVImporter105 >>> IWAeUPCSVImporter.implementedBy(FacultyCSVImporter)106 True107 108 >>> from zope.interface.verify import verifyClass109 >>> verifyClass(IWAeUPCSVImporter, FacultyCSVImporter)110 True111 112 The container is still empty:113 114 >>> len(mycontainer)115 0116 117 Now we can easily import the data:118 119 >>> importer.doImport()120 121 The container is now filled:122 123 >>> len(mycontainer)124 3125 126 >>> print [(x.code, x.title) for x in list(mycontainer.values())]127 [('AGR', 'Agriculture'), ('ART', 'Arts'), ('DEN', 'Dentistry')]128 129 130 Clean up:131 132 >>> import os133 >>> os.unlink('myfaculties.csv')
Note: See TracChangeset for help on using the changeset viewer.