Changeset 5007
- Timestamp:
- 4 Feb 2010, 12:57:32 (15 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r5005 r5007 16 16 IUniversity, IFacultyContainer, IFaculty, IDepartment, ICourse, 17 17 ICertificate, ICertificateCourse) 18 from waeup.sirp.catalog import search, search_context 18 from waeup.sirp.university.catalog import search 19 from waeup.sirp.catalog import search_context 19 20 from waeup.sirp.interfaces import( 20 21 IWAeUPObject, IUserContainer, IUserAccount, IDataCenter, -
main/waeup.sirp/trunk/src/waeup/sirp/catalog.py
r5005 r5007 5 5 from hurry.query import Eq 6 6 from waeup.sirp.app import University 7 from waeup.sirp. university.interfaces import ICourse, ICertificateCourse7 from waeup.sirp.interfaces import IQueryResultItem 8 8 from waeup.sirp.student.interfaces import IStudent 9 from zope.app.catalog.interfaces import ICatalog10 from zope.app.intid.interfaces import IIntIds11 from zope.component import getUtility12 from zope.component.interfaces import ComponentLookupError13 9 14 10 … … 18 14 grok.context(IStudent) 19 15 20 name = index.Field(attribute='name')16 name = grok.index.Field(attribute='name') 21 17 22 23 class CourseIndexes(grok.Indexes):24 grok.site(University)25 grok.name('courses_catalog')26 grok.context(ICourse)27 28 code = index.Field(attribute='code')29 title = index.Text(attribute='title')30 31 class CourseCertificatesIndexes(grok.Indexes):32 grok.site(University)33 grok.name('certcourses_catalog')34 grok.context(ICertificateCourse)35 36 course_code = index.Field(attribute='getCourseCode')37 38 @grok.subscribe(ICourse, grok.IObjectAddedEvent)39 def handleCourseAdd(obj, event):40 """Index an added course with the local catalog.41 42 Courses are not indexed automatically, as they are not a43 dictionary subitem of the accompanied site object44 (`IUniversity`). I.e. one cannot get them by asking for45 ``app['FACCODE']['DEPTCODE']['COURSECODE']`` but one has to ask for46 ``app.faculties['FACCODE']['DEPTCODE'].courses['COURSECODE']``.47 48 Once, a course is indexed we can leave the further handling to49 the default component architechture. At least removals will50 be handled correctly then (and the course unindexed).51 """52 try:53 cat = getUtility(ICatalog, name='courses_catalog')54 except ComponentLookupError:55 # catalog not available. This might happen during tests.56 return57 intids = getUtility(IIntIds)58 index = cat['code']59 index.index_doc(intids.getId(obj), obj)60 61 from zope.interface import Interface62 from zope import schema63 64 class IQueryResultItem(Interface):65 url = schema.TextLine(66 title = u'URL that links to the found item')67 title = schema.TextLine(68 title = u'Title displayed in search results.')69 description = schema.Text(70 title = u'Longer description of the item found.')71 72 73 18 class QueryResultItem(object): 74 19 grok.implements(IQueryResultItem) … … 82 27 self.title = context.title 83 28 self.description = '' 84 85 class CourseQueryResultItem(QueryResultItem):86 def __init__(self, context, view):87 self.context = context88 self.url = view.url(context)89 self.title = "COURSE: " + context.title90 self.description = 'code: %s' % context.code91 92 def search(query=None, view=None):93 if not query:94 return []95 cat = getUtility(ICatalog, name='courses_catalog')96 results = list(cat.searchResults(code=(query, query)))97 98 hitlist = []99 results = Query().searchResults(100 Eq(('courses_catalog', 'code'), query))101 for result in results:102 hitlist.append(CourseQueryResultItem(result, view=view))103 104 results = Query().searchResults(105 Text(('courses_catalog', 'title'), query))106 107 for result in results:108 hitlist.append(CourseQueryResultItem(result, view=view))109 110 return hitlist111 29 112 30 def search_context(query): -
main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py
r5004 r5007 202 202 """Emitted, when the storage of a datacenter changes. 203 203 """ 204 205 class IQueryResultItem(Interface): 206 """An item in a search result. 207 """ 208 url = schema.TextLine( 209 title = u'URL that links to the found item') 210 title = schema.TextLine( 211 title = u'Title displayed in search results.') 212 description = schema.Text( 213 title = u'Longer description of the item found.') 214
Note: See TracChangeset for help on using the changeset viewer.