Changeset 4484 for waeup/branches


Ignore:
Timestamp:
29 Jul 2009, 12:25:12 (15 years ago)
Author:
uli
Message:
  • Fix method to delete course references in certcourses.
  • Use catalog to find references to deleted courses in certcourses. These certcourses are deleted as well (as there is no course to reference any more). Seems to work perfectly with catalogs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/university/certificate.py

    r4483 r4484  
    33import grok
    44from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
     5from zope.app.catalog.interfaces import ICatalog
     6from zope.component import getUtility
    57from zope.component.interfaces import IFactory
    68from zope.interface import implementedBy
     
    5254        """Delete a course denoted by its code.
    5355        """
    54         if code in self.keys():
    55             del self[code]
     56        for key in self.keys():
     57            if self[key].getCourseCode != code:
     58                continue
     59            del self[key]
    5660            self._p_changed = True
    5761        return
     
    104108       certificatecontainer are removed.
    105109    """
    106     old_parent = event.oldParent
    107110    code = course.code
    108     # Try to find a nearby certificate container...
    109     dept = getattr(old_parent, '__parent__', None)
    110     if not IDepartment.providedBy(dept):
    111         # Hm, looks like this course was not part of a department...
    112         return
    113     certcontainer = dept.certificates
    114     for cert in certcontainer.values():
    115         # Loop through all certificatecourses in this certificate...
    116         if code in cert.keys():
    117             del cert[code]
    118             cert._p_changed = True
    119111
     112    # Find all certcourses that reference the given course...
     113    cat = getUtility(ICatalog, name='certcourses_catalog')
     114    results = cat.searchResults(course_code=(code, code))
     115    for certcourse in results:
     116        # Remove that reference...
     117        cert = certcourse.__parent__
     118        cert.delCourseRef(code)
     119        cert._p_changed = True
     120    return
Note: See TracChangeset for help on using the changeset viewer.