Ignore:
Timestamp:
28 Jul 2009, 14:07:33 (15 years ago)
Author:
uli
Message:

Add a catalog for courses. We also add an AddObjectEvent? handler,
because courses put in our deeply nested data tree will not
automatically be added to the catalog.

File:
1 edited

Legend:

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

    r4130 r4472  
    55from hurry.query import Eq
    66from waeup.app import University
     7from waeup.interfaces import ICourse
    78from waeup.student.interfaces import IStudent
     9from zope.app.catalog.interfaces import ICatalog
     10from zope.app.intid.interfaces import IIntIds
     11from zope.component import getUtility
     12from zope.component.interfaces import ComponentLookupError
     13
    814
    915class StudentIndexes(grok.Indexes):
     
    3036        return result
    3137   
     38class CourseIndexes(grok.Indexes):
     39     grok.site(University)
     40     grok.name('courses_catalog')
     41     grok.context(ICourse)
     42
     43     code = index.Field(attribute='code')
     44     title = index.Field(attribute='title')
     45
     46
     47@grok.subscribe(ICourse, grok.IObjectAddedEvent)
     48def handleCourseAdd(obj, event):
     49     """Index an added course with the local catalog.
     50
     51     Courses are not indexed automatically, as they are not a
     52     dictionary subitem of the accompanied site object
     53     (`IUniversity`). I.e. one cannot get them by asking for
     54     ``app['FACCODE']['DEPTCODE']['COURSECODE']`` but one has to ask for
     55     ``app.faculties['FACCODE']['DEPTCODE'].courses['COURSECODE']``.
     56
     57     Once, a course is indexed we can leave the further handling to
     58     the default component architechture. At least removals will
     59     be handled correctly then (and the course unindexed).
     60     """
     61     try:
     62          cat = getUtility(ICatalog, name='courses_catalog')
     63     except ComponentLookupError:
     64          # catalog not available. This might happen during tests.
     65          return
     66     intids = getUtility(IIntIds)
     67     index = cat['code']
     68     index.index_doc(intids.getId(obj), obj)
Note: See TracChangeset for help on using the changeset viewer.