Changeset 7209


Ignore:
Timestamp:
26 Nov 2011, 09:35:46 (13 years ago)
Author:
Henrik Bettermann
Message:

Add certificate removed handler. If a certificate is deleted, we make sure that also referrers to student studycourse objects are removed.

Test will follow.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7203 r7209  
    248248        source = CertificateSource(),
    249249        default = None,
    250         required = True,
     250        required = False,
    251251        )
    252252
  • main/waeup.sirp/trunk/src/waeup/sirp/university/certificate.py

    r7207 r7209  
    1919"""
    2020import grok
     21from zope.event import notify
    2122from zope.catalog.interfaces import ICatalog
    2223from zope.component import getUtility
     
    113114    def getInterfaces(self):
    114115        return implementedBy(CertificateCourse)
     116
     117@grok.subscribe(ICertificate, grok.IObjectRemovedEvent)
     118def handle_certificate_removed(certificate, event):
     119    """If a certificate is deleted, we make sure that also referrers to
     120    student studycourse objects are removed.
     121    """
     122    code = certificate.code
     123
     124    # Find all student studycourses that refer to given certificate...
     125    try:
     126        cat = getUtility(ICatalog, name='students_catalog')
     127    except ComponentLookupError:
     128        # catalog not available. This might happen during tests.
     129        return
     130
     131    results = cat.searchResults(certcode=(code, code))
     132    for student in results:
     133        # Remove that referrer...
     134        studycourse = student['studycourse']
     135        studycourse.certificate = None
     136        notify(grok.ObjectModifiedEvent(student))
     137        event_name = event.__implemented__.__name__.replace(
     138            'zope.lifecycleevent.','')
     139        student.loggerInfo(event_name, 'removed: certificate')
     140    return
Note: See TracChangeset for help on using the changeset viewer.