Changeset 4829 for waeup/branches/ulif-importers/src
- Timestamp:
- 16 Jan 2010, 13:07:56 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-importers/src/waeup/utils/batching.py
r4821 r4829 14 14 from zope.schema.interfaces import IText 15 15 from waeup.interfaces import (IImporter, IFacultyContainer, IFaculty, ICourse, 16 IDepartment, ISchemaTypeConverter, FatalCSVError) 16 IDepartment, ICertificate, ISchemaTypeConverter, 17 FatalCSVError) 17 18 18 19 class BatchProcessor(grok.GlobalUtility): … … 46 47 @property 47 48 def required_fields(self): 49 """Required fields that have no default. 50 51 A list of names of field, whose value cannot be set if not 52 given during creation. Therefore these fields must exist in 53 input. 54 55 Fields with a default != missing_value do not belong to this 56 category. 57 """ 48 58 result = [] 49 59 for key, field in getFields(self.iface).items(): 50 60 if key in self.location_fields: 61 continue 62 if field.default is not field.missing_value: 51 63 continue 52 64 if field.required: … … 162 174 163 175 def updateEntry(self, obj, row, site): 164 """Update entry given by ``row`` with data delivered therein.165 """166 r aise NotImplementedError('method not implemented')176 for key, value in row.items(): 177 setattr(obj, key, value) 178 return 167 179 168 180 def createLogfile(self, path, fail_path, num, warnings, mode, user): … … 252 264 253 265 class FacultyImporter(BatchProcessor): 266 """A batch processor for IFaculty objects. 267 """ 254 268 grok.provides(IImporter) 255 269 grok.context(Interface) … … 288 302 pass 289 303 290 def updateEntry(self, obj, row, site):291 for key, value in row.items():292 setattr(obj, key, value)293 pass294 295 304 class DepartmentImporter(BatchProcessor): 305 """A batch processor for IDepartment objects. 306 """ 296 307 grok.provides(IImporter) 297 308 grok.context(Interface) … … 335 346 return 336 347 337 def updateEntry(self, obj, row, site):338 for key, value in row.items():339 setattr(obj, key, value)340 return341 342 348 class CourseImporter(BatchProcessor): 349 """A batch processor for ICourse objects. 350 """ 343 351 grok.provides(IImporter) 344 352 grok.context(Interface) … … 386 394 return 387 395 388 def updateEntry(self, obj, row, site): 389 for key, value in row.items(): 390 setattr(obj, key, value) 391 return 392 396 class CertificateImporter(BatchProcessor): 397 """A batch processor for ICertificate objects. 398 """ 399 grok.provides(IImporter) 400 grok.context(Interface) 401 util_name = 'certificateimporter' 402 grok.name(util_name) 403 404 name = u'Certificate importer' 405 iface = ICertificate 406 407 location_fields = ['code', 'faculty_code', 'department_code'] 408 factory_name = 'waeup.Certificate' 409 410 def parentsExist(self, row, site): 411 if not 'faculties' in site.keys(): 412 return False 413 if not row['faculty_code'] in site['faculties'].keys(): 414 return False 415 faculty = site['faculties'][row['faculty_code']] 416 return row['department_code'] in faculty.keys() 417 418 def entryExists(self, row, site): 419 if not self.parentsExist(row, site): 420 return False 421 parent = self.getParent(row, site) 422 return row['code'] in parent.keys() 423 424 def getParent(self, row, site): 425 dept = site['faculties'][row['faculty_code']][row['department_code']] 426 return dept.certificates 427 428 def getEntry(self, row, site): 429 if not self.entryExists(row, site): 430 return None 431 parent = self.getParent(row, site) 432 return parent.get(row['code']) 433 434 def addEntry(self, obj, row, site): 435 parent = self.getParent(row, site) 436 parent.addCertificate(obj) 437 return 438 439 def delEntry(self, row, site): 440 parent = self.getParent(row, site) 441 del parent[row['code']] 442 return
Note: See TracChangeset for help on using the changeset viewer.