Changeset 4481 for waeup/branches


Ignore:
Timestamp:
29 Jul 2009, 01:51:36 (15 years ago)
Author:
uli
Message:

Look up courses anywhere when importing certificate courses, not only
in the same department. That's it
why we created a courses catalog in the morning.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/utils/csvimport.py

    r4471 r4481  
    66from waeup.interfaces import IFacultyContainer, IWAeUPCSVImporter
    77from waeup.utils.importexport import CSVImporter
    8 from zope.component import createObject
     8from zope.app.catalog.interfaces import ICatalog
     9from zope.component import createObject, getUtility
    910
    1011#
     
    204205            del row['department_code']
    205206
    206             course = dept.courses[code]
    207 
    208207            cert_code = row['certificate_code']
    209208            cert = dept.certificates[cert_code]
    210209            del row['certificate_code']
    211210
     211            course = self.getCourse(code)
     212           
    212213            # Type casts...
    213214            row['core_or_elective'] = toBool(row['core_or_elective'])
     
    217218        return
    218219
     220    def getCourse(self, code):
     221        """Get the course with code `code`.
     222
     223        Courses can be anywhere in the site. Therefore we ask the
     224        catalog.
     225        """
     226        cat = getUtility(ICatalog, name='courses_catalog')
     227        result = cat.searchResults(code=(code, code))
     228        if len(result) < 1:
     229            raise KeyError('No such course found: %s' % code)
     230
     231        # We might get more than one result, but this should not
     232        # happen, as course codes are supposed to be unique.
     233        return list(result)[0]
     234
     235       
Note: See TracChangeset for help on using the changeset viewer.