Changeset 4268 for waeup/branches/ulif-rewrite/src
- Timestamp:
- 12 Jun 2009, 09:57:07 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/university/facultycontainer.py
r4250 r4268 116 116 setattr(new_item, key, val) 117 117 faculty.addDepartment(new_item) 118 return 119 120 class ICourseCSVFile(ICSVFile): 121 """A CSV file that contains course data. 122 """ 123 124 class CourseCSVFile(CSVFile): 125 """An abstraction of a CSV file containing courses. 126 """ 127 grok.implements(ICourseCSVFile) 128 grok.provides(ICourseCSVFile) 129 required_fields = ['code', 'title', 'level', 'passmark', 'credits', 130 'semester', 'faculty', 'department'] 131 132 class CourseCSVImporter(CSVImporter): 133 """Shuffle data from course CSV files into faculty containers. 134 """ 135 # Tell, what kinds of objects we connect... 136 grok.adapts(ICourseCSVFile, IFacultyContainer) 137 # Tell the world, that we are an importer... 138 grok.implements(IWAeUPCSVImporter) 139 grok.provides(IWAeUPCSVImporter) 140 141 datatype = u'Course Importer' 142 143 def doImport(self, clear_old_data=True, overwrite=True): 144 # CSVImporter instances have a `csvfile` and a `receiver` 145 # object defined which refer to the CSV file and the container. 146 for row in self.csvfile.getData(): 147 new_item = createObject(u'waeup.Course') 148 faculty_code = row['faculty'] 149 faculty = self.receiver[faculty_code] 150 del row[faculty_code] 151 dept_code = row['department'] 152 dept = faculty[dept_code] 153 del row[dept_code] 154 for key, val in row.items(): 155 setattr(new_item, key, val) 156 dept.addCourse(new_item) 118 157 return 119 158
Note: See TracChangeset for help on using the changeset viewer.