Changeset 4331 for waeup/branches/ulif-rewrite
- Timestamp:
- 22 Jun 2009, 12:56:39 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/university/certificate.py
r4328 r4331 5 5 from zope.component.interfaces import IFactory 6 6 from waeup.interfaces import (ICertificate, ICertificateContainer, 7 ICertificateCourse )7 ICertificateCourse, ICourse, IDepartment) 8 8 9 9 class Certificate(grok.Container): … … 77 77 78 78 def __init__(self, course=None, level=100, core_or_elective=True): 79 # XXX Make sure, this reference is deleted, when the course80 # does not exist anymore (or the referenced course will still81 # exist here).82 79 self.course = course 83 80 self.level = level 84 81 self.core_or_elective = core_or_elective 82 83 class CertificateCourseFactory(grok.GlobalUtility): 84 """A factory for certificate courses. 85 """ 86 grok.implements(IFactory) 87 grok.name(u'waeup.CertificateCourse') 88 title = u"Create a new certificate course.", 89 description = u"This factory instantiates new certificate courses." 90 91 def __call__(self): 92 return CertificateCourse() 93 94 def getInterfaces(self): 95 return implementedBy(CertificateCourse) 96 97 @grok.subscribe(ICourse, grok.IObjectRemovedEvent) 98 def removedCourseHandler(course, event): 99 """If a course is deleted, we make sure that also references in a 100 certificatecontainer are removed. 101 """ 102 old_parent = event.oldParent 103 code = course.code 104 # Try to find a nearby certificate container... 105 dept = getattr(old_parent, '__parent__', None) 106 if not IDepartment.providedBy(dept): 107 # Hm, looks like this course was not part of a department... 108 return 109 certcontainer = dept.certificates 110 for cert in certcontainer.values(): 111 # Loop through all certificatecourses in this certificate... 112 if code in cert.keys(): 113 del cert[code] 114 cert._p_changed = True 115
Note: See TracChangeset for help on using the changeset viewer.