Ignore:
Timestamp:
22 Jun 2009, 15:28:38 (16 years ago)
Author:
uli
Message:

Add importer for certcourses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/university/facultycontainer.py

    r4329 r4335  
    202202                setattr(new_item, key, val)
    203203            dept.certificates.addCertificate(new_item)
     204        return
     205
     206class ICertificateCourseCSVFile(ICSVFile):
     207    """A CSV file that contains certificate-course data.
     208    """
     209
     210class 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
     218class 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            cert.addCourseRef(course, **row)
    204253        return
    205254
Note: See TracChangeset for help on using the changeset viewer.