Changeset 5007 for main


Ignore:
Timestamp:
4 Feb 2010, 12:57:32 (15 years ago)
Author:
uli
Message:
  • Move academics-related catalog components into university subpackage.
  • Move interface into interfaces.py where it belongs.
  • Update pages.py to reflect the changes above.
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  
    1616    IUniversity, IFacultyContainer, IFaculty, IDepartment, ICourse,
    1717    ICertificate, ICertificateCourse)
    18 from waeup.sirp.catalog import search, search_context
     18from waeup.sirp.university.catalog import search
     19from waeup.sirp.catalog import search_context
    1920from waeup.sirp.interfaces import(
    2021    IWAeUPObject, IUserContainer, IUserAccount, IDataCenter,
  • main/waeup.sirp/trunk/src/waeup/sirp/catalog.py

    r5005 r5007  
    55from hurry.query import Eq
    66from waeup.sirp.app import University
    7 from waeup.sirp.university.interfaces import ICourse, ICertificateCourse
     7from waeup.sirp.interfaces import IQueryResultItem
    88from waeup.sirp.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
    139
    1410
     
    1814     grok.context(IStudent)
    1915
    20      name = index.Field(attribute='name')
     16     name = grok.index.Field(attribute='name')
    2117
    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 a
    43      dictionary subitem of the accompanied site object
    44      (`IUniversity`). I.e. one cannot get them by asking for
    45      ``app['FACCODE']['DEPTCODE']['COURSECODE']`` but one has to ask for
    46      ``app.faculties['FACCODE']['DEPTCODE'].courses['COURSECODE']``.
    47 
    48      Once, a course is indexed we can leave the further handling to
    49      the default component architechture. At least removals will
    50      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           return
    57      intids = getUtility(IIntIds)
    58      index = cat['code']
    59      index.index_doc(intids.getId(obj), obj)
    60 
    61 from zope.interface import Interface
    62 from zope import schema
    63 
    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      
    7318class QueryResultItem(object):
    7419     grok.implements(IQueryResultItem)
     
    8227          self.title = context.title
    8328          self.description = ''
    84      
    85 class CourseQueryResultItem(QueryResultItem):
    86      def __init__(self, context, view):
    87           self.context = context
    88           self.url = view.url(context)
    89           self.title = "COURSE: " + context.title
    90           self.description = 'code: %s' % context.code
    91 
    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 hitlist
    11129
    11230def search_context(query):
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r5004 r5007  
    202202    """Emitted, when the storage of a datacenter changes.
    203203    """
     204
     205class 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.