Ignore:
Timestamp:
29 May 2011, 09:23:30 (13 years ago)
Author:
Henrik Bettermann
Message:

Course codes must be unique. Check catalog when courses are added. Flash the place where course exists.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/university/coursecontainer.py

    r5005 r6216  
    33import grok
    44from zope.interface import implementedBy
    5 from zope.component.interfaces import IFactory
     5from zope.component.interfaces import IFactory, ComponentLookupError
     6from zope.catalog.interfaces import ICatalog
     7from zope.component import getUtility
    68from waeup.sirp.university.interfaces import ICourseContainer, ICourse
    79
     
    1719        if not ICourse.providedBy(course):
    1820            raise TypeError('CourseContainers contain only ICourse instances')
     21        try:
     22            cat = getUtility(ICatalog, name='courses_catalog')
     23        except ComponentLookupError:
     24            # catalog not available. This might happen during tests.
     25            self[course.code] = course
     26            return 'Course added (for tests only).'
     27        results = list(cat.searchResults(code=(course.code,course.code)))
     28        if results:
     29            dep = results[0].__parent__.__parent__.longtitle()
     30            fac = results[0].__parent__.__parent__.__parent__.longtitle()
     31            return 'Course exists already in %s / %s.' % (fac,dep)
    1932        self[course.code] = course
    20         return
     33        return 'Course added.'
    2134
    2235    def clear(self):
Note: See TracChangeset for help on using the changeset viewer.