Ignore:
Timestamp:
26 Nov 2011, 08:54:59 (13 years ago)
Author:
Henrik Bettermann
Message:

Move course removed handler to course module.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/university
Files:
2 edited

Legend:

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

    r7195 r7207  
    2424from zope.interface import implementedBy
    2525from waeup.sirp.university.interfaces import (
    26     ICertificate, ICertificateAdd, ICertificateCourse, ICourse)
     26    ICertificate, ICertificateAdd, ICertificateCourse)
    2727from waeup.sirp.university.vocabularies import course_levels   
    2828
     
    113113    def getInterfaces(self):
    114114        return implementedBy(CertificateCourse)
    115 
    116 @grok.subscribe(ICourse, grok.IObjectRemovedEvent)
    117 def handle_course_removed(course, event):
    118     """If a course is deleted, we make sure that also referrers in a
    119        certificatecontainer are removed.
    120     """
    121     code = course.code
    122 
    123     # Find all certificatecourses that refer to given course...
    124     try:
    125         cat = getUtility(ICatalog, name='certcourses_catalog')
    126     except ComponentLookupError:
    127         # catalog not available. This might happen during tests.
    128         return
    129        
    130     results = cat.searchResults(course_code=(code, code))
    131     for certcourse in results:
    132         # Remove that referrer...
    133         cert = certcourse.__parent__
    134         cert.delCourseRef(code)
    135         cert._p_changed = True
    136     return
  • main/waeup.sirp/trunk/src/waeup/sirp/university/course.py

    r7195 r7207  
    1919"""
    2020import grok
     21from zope.catalog.interfaces import ICatalog
    2122from zope.interface import implementedBy
    22 from zope.component.interfaces import IFactory
     23from zope.component import getUtility
     24from zope.component.interfaces import IFactory, ComponentLookupError
    2325from waeup.sirp.university.interfaces import ICourse, ICourseAdd
    2426
     
    5759    def getInterfaces(self):
    5860        return implementedBy(Course)
     61
     62@grok.subscribe(ICourse, grok.IObjectRemovedEvent)
     63def handle_course_removed(course, event):
     64    """If a course is deleted, we make sure that also referrers in a
     65       certificatecontainer are removed.
     66    """
     67    code = course.code
     68
     69    # Find all certificatecourses that refer to given course...
     70    try:
     71        cat = getUtility(ICatalog, name='certcourses_catalog')
     72    except ComponentLookupError:
     73        # catalog not available. This might happen during tests.
     74        return
     75
     76    results = cat.searchResults(course_code=(code, code))
     77    for certcourse in results:
     78        # Remove that referrer...
     79        cert = certcourse.__parent__
     80        cert.delCourseRef(code)
     81        cert._p_changed = True
     82    return
Note: See TracChangeset for help on using the changeset viewer.