Changeset 4389
- Timestamp:
- 2 Jul 2009, 09:43:04 (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.py
r4341 r4389 45 45 def getInterfaces(self): 46 46 return implementedBy(FacultyContainer) 47 48 49 #50 # CSV import stuff51 #52 class IFacultyCSVFile(ICSVFile):53 """A CSV file that contains faculty data.54 """55 56 class FacultyCSVFile(CSVFile):57 """An abstraction of a CSV file containing faculties.58 """59 grok.implements(IFacultyCSVFile)60 grok.provides(IFacultyCSVFile)61 required_fields = ['code', 'title', 'title_prefix']62 63 class FacultyCSVImporter(CSVImporter):64 """Shuffle data from faculty CSV files into faculty containers.65 """66 # Tell, what kinds of objects we connect...67 grok.adapts(IFacultyCSVFile, IFacultyContainer)68 # Tell the world, that we are an importer...69 grok.implements(IWAeUPCSVImporter)70 grok.provides(IWAeUPCSVImporter)71 72 datatype = u'Faculty Importer'73 74 def doImport(self, clear_old_data=True, overwrite=True):75 # CSVImporter instances have a `csvfile` and a `receiver`76 # object defined which refer to the CSV file and the container.77 for row in self.csvfile.getData():78 new_item = createObject(u'waeup.Faculty')79 for key, val in row.items():80 setattr(new_item, key, val)81 self.receiver.addFaculty(new_item)82 return83 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 departments.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 faculty_code = row['faculty_code']112 faculty = self.receiver[faculty_code]113 del row['faculty_code']114 for key, val in row.items():115 setattr(new_item, key, val)116 faculty.addDepartment(new_item)117 return118 119 class ICourseCSVFile(ICSVFile):120 """A CSV file that contains course data.121 """122 123 class CourseCSVFile(CSVFile):124 """An abstraction of a CSV file containing courses.125 """126 grok.implements(ICourseCSVFile)127 grok.provides(ICourseCSVFile)128 required_fields = ['code', 'title', 'level', 'passmark', 'credits',129 'semester', 'faculty', 'department']130 131 class CourseCSVImporter(CSVImporter):132 """Shuffle data from course CSV files into faculty containers.133 """134 # Tell, what kinds of objects we connect...135 grok.adapts(ICourseCSVFile, IFacultyContainer)136 # Tell the world, that we are an importer...137 grok.implements(IWAeUPCSVImporter)138 grok.provides(IWAeUPCSVImporter)139 140 datatype = u'Course Importer'141 142 def doImport(self, clear_old_data=True, overwrite=True):143 # CSVImporter instances have a `csvfile` and a `receiver`144 # object defined which refer to the CSV file and the container.145 for row in self.csvfile.getData():146 147 new_item = createObject(u'waeup.Course')148 149 faculty_code = row['faculty']150 faculty = self.receiver[faculty_code]151 del row['faculty']152 153 dept_code = row['department']154 dept = faculty[dept_code]155 del row['department']156 157 for key, val in row.items():158 setattr(new_item, key, val)159 dept.courses.addCourse(new_item)160 return161 162 class ICertificateCSVFile(ICSVFile):163 """A CSV file that contains certificate data.164 """165 166 class CertificateCSVFile(CSVFile):167 """An abstraction of a CSV file containing certificates.168 """169 grok.implements(ICertificateCSVFile)170 grok.provides(ICertificateCSVFile)171 required_fields = ['code', 'title', 'faculty_code', 'department_code',172 'category', 'study_mode', 'start_level', 'end_level',173 'm_prefix', 'max_pass', 'application_category']174 175 class CertificateCSVImporter(CSVImporter):176 """Shuffle data from certificate CSV files into faculty containers.177 """178 # Tell, what kinds of objects we connect...179 grok.adapts(ICertificateCSVFile, IFacultyContainer)180 # Tell the world, that we are an importer...181 grok.implements(IWAeUPCSVImporter)182 grok.provides(IWAeUPCSVImporter)183 184 datatype = u'Certificate Importer'185 186 def doImport(self, clear_old_data=True, overwrite=True):187 # CSVImporter instances have a `csvfile` and a `receiver`188 # object defined which refer to the CSV file and the container.189 for row in self.csvfile.getData():190 191 new_item = createObject(u'waeup.Certificate')192 193 faculty_code = row['faculty_code']194 faculty = self.receiver[faculty_code]195 del row['faculty_code']196 197 dept_code = row['department_code']198 dept = faculty[dept_code]199 del row['department_code']200 201 for key, val in row.items():202 setattr(new_item, key, val)203 dept.certificates.addCertificate(new_item)204 return205 206 class ICertificateCourseCSVFile(ICSVFile):207 """A CSV file that contains certificate-course data.208 """209 210 class CertificateCourseCSVFile(CSVFile):211 """An abstraction of a CSV file containing certificate-courses.212 """213 grok.implements(ICertificateCourseCSVFile)214 grok.provides(ICertificateCourseCSVFile)215 required_fields = ['code', 'faculty_code', 'department_code',216 'certificate_code', 'level', 'core_or_elective']217 218 class CertificateCourseCSVImporter(CSVImporter):219 """Shuffle data from certificate CSV files into faculty containers.220 """221 # Tell, what kinds of objects we connect...222 grok.adapts(ICertificateCourseCSVFile, IFacultyContainer)223 # Tell the world, that we are an importer...224 grok.implements(IWAeUPCSVImporter)225 grok.provides(IWAeUPCSVImporter)226 227 datatype = u'Certificate Importer'228 229 def doImport(self, clear_old_data=True, overwrite=True):230 # CSVImporter instances have a `csvfile` and a `receiver`231 # object defined which refer to the CSV file and the container.232 for row in self.csvfile.getData():233 234 new_item = createObject(u'waeup.CertificateCourse')235 code = row['code']236 del row['code']237 238 faculty_code = row['faculty_code']239 faculty = self.receiver[faculty_code]240 del row['faculty_code']241 242 dept_code = row['department_code']243 dept = faculty[dept_code]244 del row['department_code']245 246 course = dept.courses[code]247 248 cert_code = row['certificate_code']249 cert = dept.certificates[cert_code]250 del row['certificate_code']251 252 # Type casts...253 row['core_or_elective'] = toBool(row['core_or_elective'])254 row['level'] = int(row['level'])255 256 cert.addCourseRef(course, **row)257 return258 259 47 260 48
Note: See TracChangeset for help on using the changeset viewer.