Ignore:
Timestamp:
28 May 2011, 07:19:57 (14 years ago)
Author:
Henrik Bettermann
Message:

Fix indentation. We use only 4 whitespaces not 5. Remove #BBB.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/catalog.py

    r6116 r6207  
    1515
    1616class WAeUPQuery(Query):
    17      """A hurry.query-like query that supports also ``apply``.
    18      """
    19      grok.implements(IQuery)
     17    """A hurry.query-like query that supports also ``apply``.
     18    """
     19    grok.implements(IQuery)
    2020
    21      def apply(self, query):
    22           """Get a catalog's BTree set of intids conforming to a query.
    23           """
    24           return query.apply()
     21    def apply(self, query):
     22        """Get a catalog's BTree set of intids conforming to a query.
     23        """
     24        return query.apply()
    2525
    26      def searchResults(self, query):
    27           """Get a set of ZODB objects conforming to a query.
    28           """
    29           results = self.apply(query)
    30           if results is not None:
    31                uidutil = getUtility(IIntIds)
    32                results = ResultSet(results, uidutil)
    33           return results
     26    def searchResults(self, query):
     27        """Get a set of ZODB objects conforming to a query.
     28        """
     29        results = self.apply(query)
     30        if results is not None:
     31            uidutil = getUtility(IIntIds)
     32            results = ResultSet(results, uidutil)
     33        return results
    3434
    3535grok.global_utility(WAeUPQuery)
    3636
     37class StudentIndexes(grok.Indexes):
     38    grok.site(University)
     39    grok.name('students_catalog')
     40    grok.context(IStudent)
    3741
    38 class StudentIndexes(grok.Indexes):
    39      grok.site(University)
    40      grok.name('students_catalog')
    41      grok.context(IStudent)
    42 
    43      name = grok.index.Field(attribute='name')
     42    name = grok.index.Field(attribute='name')
    4443
    4544class QueryResultItem(object):
    46      grok.implements(IQueryResultItem)
    47      url = None
    48      title = None
    49      description = None
     45    grok.implements(IQueryResultItem)
     46    url = None
     47    title = None
     48    description = None
    5049
    51      def __init__(self, context, view):
    52           self.context = context
    53           self.url = view.url(context)
    54           self.title = context.title
    55           self.description = ''
     50    def __init__(self, context, view):
     51        self.context = context
     52        self.url = view.url(context)
     53        self.title = context.title
     54        self.description = ''
    5655
    5756def search_context(query):
    58      result = Query().searchResults(
    59           Eq(('students_catalog', 'name'), query)
    60           )
    61      return result
     57    result = Query().searchResults(
     58        Eq(('students_catalog', 'name'), query)
     59        )
     60    return result
  • main/waeup.sirp/trunk/src/waeup/sirp/university/catalog.py

    r5992 r6207  
    33import grok
    44from hurry.query import Eq
    5 try:
    6      from zope.catalog.interfaces import ICatalog
    7 except ImportError:
    8      # BBB
    9      from zope.app.catalog.interfaces import ICatalog
     5from zope.catalog.interfaces import ICatalog
    106from zope.component import getUtility
    117from zope.component.interfaces import ComponentLookupError
    12 try:
    13      from zope.intid import IIntIds
    14 except ImportError:
    15      # BBB
    16      from zope.app.intid.interfaces import IIntIds
     8from zope.intid import IIntIds
    179from waeup.sirp.interfaces import IUniversity
    1810from waeup.sirp.catalog import QueryResultItem
    1911from waeup.sirp.university.interfaces import (
    20      ICourse, ICertificateCourse, IDepartment,
    21      )
     12    ICourse, ICertificateCourse, IDepartment,
     13    )
    2214
    2315class CourseIndexes(grok.Indexes):
    24      grok.site(IUniversity)
    25      grok.name('courses_catalog')
    26      grok.context(ICourse)
     16    grok.site(IUniversity)
     17    grok.name('courses_catalog')
     18    grok.context(ICourse)
    2719
    28      code = grok.index.Field(attribute='code')
    29      title = grok.index.Text(attribute='title')
     20    code = grok.index.Field(attribute='code')
     21    title = grok.index.Text(attribute='title')
    3022
    3123class CourseCertificatesIndexes(grok.Indexes):
    32      grok.site(IUniversity)
    33      grok.name('certcourses_catalog')
    34      grok.context(ICertificateCourse)
     24    grok.site(IUniversity)
     25    grok.name('certcourses_catalog')
     26    grok.context(ICertificateCourse)
    3527
    36      course_code = grok.index.Field(attribute='getCourseCode')
     28    course_code = grok.index.Field(attribute='getCourseCode')
    3729
    3830@grok.subscribe(ICourse, grok.IObjectAddedEvent)
    3931def handleCourseAdd(obj, event):
    40      """Index an added course with the local catalog.
     32    """Index an added course with the local catalog.
    4133
    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']``.
     34    Courses are not indexed automatically, as they are not a
     35    dictionary subitem of the accompanied site object
     36    (`IUniversity`). I.e. one cannot get them by asking for
     37    ``app['FACCODE']['DEPTCODE']['COURSECODE']`` but one has to ask for
     38    ``app.faculties['FACCODE']['DEPTCODE'].courses['COURSECODE']``.
    4739
    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)
     40    Once, a course is indexed we can leave the further handling to
     41    the default component architechture. At least removals will
     42    be handled correctly then (and the course unindexed).
     43    """
     44    try:
     45        cat = getUtility(ICatalog, name='courses_catalog')
     46    except ComponentLookupError:
     47        # catalog not available. This might happen during tests.
     48        return
     49    intids = getUtility(IIntIds)
     50    index = cat['code']
     51    index.index_doc(intids.getId(obj), obj)
    6052
    6153@grok.subscribe(IDepartment, grok.IObjectRemovedEvent)
    6254def handleDepartmentRemoval(obj, event):
    63      """Clear courses and certificates when a department is killed.
    64      """
    65      obj.courses.clear()
    66      obj.certificates.clear()
    67      return
     55    """Clear courses and certificates when a department is killed.
     56    """
     57    obj.courses.clear()
     58    obj.certificates.clear()
     59    return
    6860
    6961class CourseQueryResultItem(QueryResultItem):
    70      def __init__(self, context, view):
    71           self.context = context
    72           self.url = view.url(context)
    73           self.title = "COURSE: " + context.title
    74           self.description = 'code: %s' % context.code
     62    def __init__(self, context, view):
     63        self.context = context
     64        self.url = view.url(context)
     65        self.title = "COURSE: " + context.title
     66        self.description = 'code: %s' % context.code
    7567
    7668def search(query=None, view=None):
    77      if not query:
    78           return []
    79      cat = getUtility(ICatalog, name='courses_catalog')
    80      results = list(cat.searchResults(code=(query, query)))
    81          
    82      hitlist = []
    83      results = Query().searchResults(
    84           Eq(('courses_catalog', 'code'), query))
    85      for result in results:
    86           hitlist.append(CourseQueryResultItem(result, view=view))
     69    if not query:
     70        return []
     71    cat = getUtility(ICatalog, name='courses_catalog')
     72    results = list(cat.searchResults(code=(query, query)))
    8773
    88      results = Query().searchResults(
    89           Text(('courses_catalog', 'title'), query))
    90          
    91      for result in results:
    92           hitlist.append(CourseQueryResultItem(result, view=view))
     74    hitlist = []
     75    results = Query().searchResults(
     76        Eq(('courses_catalog', 'code'), query))
     77    for result in results:
     78        hitlist.append(CourseQueryResultItem(result, view=view))
    9379
    94      return hitlist
     80    results = Query().searchResults(
     81        Text(('courses_catalog', 'title'), query))
     82
     83    for result in results:
     84        hitlist.append(CourseQueryResultItem(result, view=view))
     85
     86    return hitlist
Note: See TracChangeset for help on using the changeset viewer.