Changeset 4250
- Timestamp:
- 11 Jun 2009, 13:17:06 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/university/facultycontainer.py
r4236 r4250 80 80 setattr(new_item, key, val) 81 81 self.receiver.addFaculty(new_item) 82 return 83 84 class IDepartmentCSVFile(ICSVFile): 85 """A CSV file that contains department data. 86 """ 87 88 class DepartmentCSVFile(CSVFile): 89 """An abstraction of a CSV file containing faculties. 90 """ 91 grok.implements(IDepartmentCSVFile) 92 grok.provides(IDepartmentCSVFile) 93 required_fields = ['code', 'title', 'title_prefix', 'faculty_code'] 94 95 class DepartmentCSVImporter(CSVImporter): 96 """Shuffle data from department CSV files into faculty containers. 97 """ 98 # Tell, what kinds of objects we connect... 99 grok.adapts(IDepartmentCSVFile, IFacultyContainer) 100 # Tell the world, that we are an importer... 101 grok.implements(IWAeUPCSVImporter) 102 grok.provides(IWAeUPCSVImporter) 103 104 datatype = u'Department Importer' 105 106 def doImport(self, clear_old_data=True, overwrite=True): 107 # CSVImporter instances have a `csvfile` and a `receiver` 108 # object defined which refer to the CSV file and the container. 109 for row in self.csvfile.getData(): 110 new_item = createObject(u'waeup.Department') 111 #data = row.items() 112 faculty_code = row['faculty_code'] 113 faculty = self.receiver[faculty_code] 114 del row['faculty_code'] 115 for key, val in row.items(): 116 setattr(new_item, key, val) 117 faculty.addDepartment(new_item) 82 118 return 83 119
Note: See TracChangeset for help on using the changeset viewer.