Ignore:
Timestamp:
4 Feb 2010, 13:48:45 (15 years ago)
Author:
uli
Message:

Move academics-specific components from utils.batching to university.batching.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/batching.py

    r5005 r5009  
    1414from zope.interface import Interface
    1515from zope.schema import getFields
    16 from zope.schema.interfaces import IText
    1716from waeup.sirp.interfaces import (
    1817    IBatchProcessor, ISchemaTypeConverter, FatalCSVError)
    19 from waeup.sirp.university.interfaces import (
    20     IFacultyContainer, IFaculty, ICourse, IDepartment, ICertificate,
    21     ICertificateCourse)
    2218
    2319class BatchProcessor(grok.GlobalUtility):
     
    3127
    3228    # Name used in pages and forms...
    33     name = u'Department importer'
     29    name = u'Non-registered base importer'
    3430   
    3531    # Internal name...
    36     util_name = 'departmentimporter'
     32    util_name = 'baseimporter'
    3733   
    3834    # Items for this processor need an interface with zope.schema fields.
    39     iface = IDepartment
     35    iface = Interface
    4036   
    4137    # The name must be the same as the util_name attribute in order to
     
    168164
    169165    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):
    170171        """Get the parent object for the entry in ``row``.
    171172        """
     
    315316        return (num, num_warns,
    316317                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 = IFaculty
    328 
    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 None
    344         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         return
    351 
    352     def delEntry(self, row, site):
    353         parent = self.getParent(row, site)
    354         del parent[row['code']]
    355         pass
    356 
    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 = IDepartment
    367 
    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 False
    374         return row['faculty_code'] in site['faculties']
    375 
    376     def entryExists(self, row, site):
    377         if not self.parentsExist(row, site):
    378             return False
    379         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 None
    388         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         return
    395 
    396     def delEntry(self, row, site):
    397         parent = self.getParent(row, site)
    398         del parent[row['code']]
    399         return
    400 
    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 = ICourse
    411 
    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 False
    418         if not row['faculty_code'] in site['faculties'].keys():
    419             return False
    420         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 False
    426         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.courses
    432 
    433     def getEntry(self, row, site):
    434         if not self.entryExists(row, site):
    435             return None
    436         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         return
    443 
    444     def delEntry(self, row, site):
    445         parent = self.getParent(row, site)
    446         del parent[row['code']]
    447         return
    448 
    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 = ICertificate
    459 
    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 False
    466         if not row['faculty_code'] in site['faculties'].keys():
    467             return False
    468         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 False
    474         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.certificates
    480 
    481     def getEntry(self, row, site):
    482         if not self.entryExists(row, site):
    483             return None
    484         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         return
    491 
    492     def delEntry(self, row, site):
    493         parent = self.getParent(row, site)
    494         del parent[row['code']]
    495         return
    496 
    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 = ICertificateCourse
    507 
    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 False
    515         if not row['faculty_code'] in site['faculties'].keys():
    516             return False
    517         faculty = site['faculties'][row['faculty_code']]
    518         if not row['department_code'] in faculty.keys():
    519             return False
    520         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 False
    526         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 None
    537         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         return
    545 
    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.