Changeset 4472
- Timestamp:
- 28 Jul 2009, 14:07:33 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/catalog.py
r4130 r4472 5 5 from hurry.query import Eq 6 6 from waeup.app import University 7 from waeup.interfaces import ICourse 7 8 from waeup.student.interfaces import IStudent 9 from zope.app.catalog.interfaces import ICatalog 10 from zope.app.intid.interfaces import IIntIds 11 from zope.component import getUtility 12 from zope.component.interfaces import ComponentLookupError 13 8 14 9 15 class StudentIndexes(grok.Indexes): … … 30 36 return result 31 37 38 class 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) 48 def 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.