Changeset 5009 for main/waeup.sirp/trunk/src/waeup/sirp/utils
- Timestamp:
- 4 Feb 2010, 13:48:45 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/utils/batching.py
r5005 r5009 14 14 from zope.interface import Interface 15 15 from zope.schema import getFields 16 from zope.schema.interfaces import IText17 16 from waeup.sirp.interfaces import ( 18 17 IBatchProcessor, ISchemaTypeConverter, FatalCSVError) 19 from waeup.sirp.university.interfaces import (20 IFacultyContainer, IFaculty, ICourse, IDepartment, ICertificate,21 ICertificateCourse)22 18 23 19 class BatchProcessor(grok.GlobalUtility): … … 31 27 32 28 # Name used in pages and forms... 33 name = u' Departmentimporter'29 name = u'Non-registered base importer' 34 30 35 31 # Internal name... 36 util_name = ' departmentimporter'32 util_name = 'baseimporter' 37 33 38 34 # Items for this processor need an interface with zope.schema fields. 39 iface = I Department35 iface = Interface 40 36 41 37 # The name must be the same as the util_name attribute in order to … … 168 164 169 165 def getParent(self, row, site): 166 """Get the parent object for the entry in ``row``. 167 """ 168 raise NotImplementedError('method not implemented') 169 170 def getEntry(self, row, site): 170 171 """Get the parent object for the entry in ``row``. 171 172 """ … … 315 316 return (num, num_warns, 316 317 os.path.abspath(finished_path), failed_path) 317 318 class FacultyProcessor(BatchProcessor):319 """A batch processor for IFaculty objects.320 """321 grok.provides(IBatchProcessor)322 grok.context(Interface)323 util_name = 'facultyimporter'324 grok.name(util_name)325 326 name = u'Faculty importer'327 iface = IFaculty328 329 location_fields = ['code',]330 factory_name = 'waeup.Faculty'331 332 def parentsExist(self, row, site):333 return 'faculties' in site.keys()334 335 def entryExists(self, row, site):336 return row['code'] in site['faculties'].keys()337 338 def getParent(self, row, site):339 return site['faculties']340 341 def getEntry(self, row, site):342 if not self.entryExists(row, site):343 return None344 parent = self.getParent(row, site)345 return parent.get(row['code'])346 347 def addEntry(self, obj, row, site):348 parent = self.getParent(row, site)349 parent.addFaculty(obj)350 return351 352 def delEntry(self, row, site):353 parent = self.getParent(row, site)354 del parent[row['code']]355 pass356 357 class DepartmentProcessor(BatchProcessor):358 """A batch processor for IDepartment objects.359 """360 grok.provides(IBatchProcessor)361 grok.context(Interface)362 util_name = 'departmentimporter'363 grok.name(util_name)364 365 name = u'Department importer'366 iface = IDepartment367 368 location_fields = ['code', 'faculty_code']369 factory_name = 'waeup.Department'370 371 def parentsExist(self, row, site):372 if not 'faculties' in site.keys():373 return False374 return row['faculty_code'] in site['faculties']375 376 def entryExists(self, row, site):377 if not self.parentsExist(row, site):378 return False379 parent = self.getParent(row, site)380 return row['code'] in parent.keys()381 382 def getParent(self, row, site):383 return site['faculties'][row['faculty_code']]384 385 def getEntry(self, row, site):386 if not self.entryExists(row, site):387 return None388 parent = self.getParent(row, site)389 return parent.get(row['code'])390 391 def addEntry(self, obj, row, site):392 parent = self.getParent(row, site)393 parent.addDepartment(obj)394 return395 396 def delEntry(self, row, site):397 parent = self.getParent(row, site)398 del parent[row['code']]399 return400 401 class CourseProcessor(BatchProcessor):402 """A batch processor for ICourse objects.403 """404 grok.provides(IBatchProcessor)405 grok.context(Interface)406 util_name = 'courseimporter'407 grok.name(util_name)408 409 name = u'Course importer'410 iface = ICourse411 412 location_fields = ['code', 'faculty_code', 'department_code']413 factory_name = 'waeup.Course'414 415 def parentsExist(self, row, site):416 if not 'faculties' in site.keys():417 return False418 if not row['faculty_code'] in site['faculties'].keys():419 return False420 faculty = site['faculties'][row['faculty_code']]421 return row['department_code'] in faculty.keys()422 423 def entryExists(self, row, site):424 if not self.parentsExist(row, site):425 return False426 parent = self.getParent(row, site)427 return row['code'] in parent.keys()428 429 def getParent(self, row, site):430 dept = site['faculties'][row['faculty_code']][row['department_code']]431 return dept.courses432 433 def getEntry(self, row, site):434 if not self.entryExists(row, site):435 return None436 parent = self.getParent(row, site)437 return parent.get(row['code'])438 439 def addEntry(self, obj, row, site):440 parent = self.getParent(row, site)441 parent.addCourse(obj)442 return443 444 def delEntry(self, row, site):445 parent = self.getParent(row, site)446 del parent[row['code']]447 return448 449 class CertificateProcessor(BatchProcessor):450 """A batch processor for ICertificate objects.451 """452 grok.provides(IBatchProcessor)453 grok.context(Interface)454 util_name = 'certificateimporter'455 grok.name(util_name)456 457 name = u'Certificate importer'458 iface = ICertificate459 460 location_fields = ['code', 'faculty_code', 'department_code']461 factory_name = 'waeup.Certificate'462 463 def parentsExist(self, row, site):464 if not 'faculties' in site.keys():465 return False466 if not row['faculty_code'] in site['faculties'].keys():467 return False468 faculty = site['faculties'][row['faculty_code']]469 return row['department_code'] in faculty.keys()470 471 def entryExists(self, row, site):472 if not self.parentsExist(row, site):473 return False474 parent = self.getParent(row, site)475 return row['code'] in parent.keys()476 477 def getParent(self, row, site):478 dept = site['faculties'][row['faculty_code']][row['department_code']]479 return dept.certificates480 481 def getEntry(self, row, site):482 if not self.entryExists(row, site):483 return None484 parent = self.getParent(row, site)485 return parent.get(row['code'])486 487 def addEntry(self, obj, row, site):488 parent = self.getParent(row, site)489 parent.addCertificate(obj)490 return491 492 def delEntry(self, row, site):493 parent = self.getParent(row, site)494 del parent[row['code']]495 return496 497 class CertificateCourseProcessor(BatchProcessor):498 """A batch processor for ICertificateCourse objects.499 """500 grok.provides(IBatchProcessor)501 grok.context(Interface)502 util_name = 'certificatecourseimporter'503 grok.name(util_name)504 505 name = u'CertificateCourse importer'506 iface = ICertificateCourse507 508 location_fields = ['course', 'level', 'faculty_code', 'department_code',509 'certificate_code',]510 factory_name = 'waeup.CertificateCourse'511 512 def parentsExist(self, row, site):513 if not 'faculties' in site.keys():514 return False515 if not row['faculty_code'] in site['faculties'].keys():516 return False517 faculty = site['faculties'][row['faculty_code']]518 if not row['department_code'] in faculty.keys():519 return False520 dept = faculty[row['department_code']]521 return row['certificate_code'] in dept.certificates.keys()522 523 def entryExists(self, row, site):524 if not self.parentsExist(row, site):525 return False526 parent = self.getParent(row, site)527 code = "%s_%s" % (row['course'].code, row['level'])528 return code in parent.keys()529 530 def getParent(self, row, site):531 dept = site['faculties'][row['faculty_code']][row['department_code']]532 return dept.certificates[row['certificate_code']]533 534 def getEntry(self, row, site):535 if not self.entryExists(row, site):536 return None537 parent = self.getParent(row, site)538 return parent.get(row['course'])539 540 def addEntry(self, obj, row, site):541 parent = self.getParent(row, site)542 parent.addCourseRef(row['course'],543 row['level'], row['core_or_elective'])544 return545 546 def delEntry(self, row, site):547 parent = self.getParent(row, site)548 parent.delCourseRef(row['course'].code, row['level'])549 return
Note: See TracChangeset for help on using the changeset viewer.