Ignore:
Timestamp:
4 Jan 2010, 22:48:15 (15 years ago)
Author:
uli
Message:

Add search views as pages and related helpers. This still needs a lot
of cleanup!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/browser/pages.py

    r4648 r4661  
    33"""
    44import grok
     5from hurry.query import Eq
     6from hurry.query.query import Query, Text
    57from waeup.browser import WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage
    68from waeup.interfaces import (IUniversity, IWAeUPObject, IUserContainer,
     
    184186        return
    185187
     188#
     189# Search pages...
     190#
     191class SearchStudentPage(WAeUPPage):
     192    grok.context(IUniversity)
     193    grok.name('searchstudent')
     194    grok.template('searchstudentpage')
     195    grok.require('waeup.View')
     196    pnav = 2
     197
     198    def update(self, query=None):
     199        self.search_result = []
     200        if query is not None:
     201            self.search_result = self.search_context(query)
     202            print "RESULT: ", list(self.search_result)
     203
     204    def search_context(self, query):
     205        result = Query().searchResults(
     206            Eq(('students_catalog', 'name'), query)
     207            )
     208        return result
     209
     210from zope.interface import Interface
     211from zope import schema
     212
     213class IQueryResultItem(Interface):
     214     url = schema.TextLine(
     215          title = u'URL that links to the found item')
     216     title = schema.TextLine(
     217          title = u'Title displayed in search results.')
     218     description = schema.Text(
     219          title = u'Longer description of the item found.')
     220     
     221     
     222class QueryResultItem(object):
     223     grok.implements(IQueryResultItem)
     224     url = None
     225     title = None
     226     description = None
     227     
     228     def __init__(self, context, view):
     229          self.context = context
     230          self.url = view.url(context)
     231          self.title = context.title
     232          self.description = ''
     233     
     234class CourseQueryResultItem(QueryResultItem):
     235     def __init__(self, context, view):
     236          self.context = context
     237          self.url = view.url(context)
     238          self.title = "COURSE: " + context.title
     239          self.description = 'code: %s' % context.code
     240
     241
     242#from waeup.viewlets import Search, MainArea
     243from hurry.query.query import Query, Text, Eq
     244from zope.app.catalog.interfaces import ICatalog
     245
     246class SearchPage(WAeUPPage):
     247     grok.context(IUniversity)
     248     grok.name('search')
     249     grok.template('searchpage')
     250     grok.require('waeup.View')
     251
     252     def update(self, *args, **kw):
     253          #print "UPDATE: ", args, kw
     254          #print self.request.form
     255          form = self.request.form
     256          self.hitlist = []
     257          self.query = ''
     258          if not 'query' in form:
     259               return
     260          query = form['query']
     261          self.query = query
     262          cat = getUtility(ICatalog, name='courses_catalog')
     263          #print "CODES: ",  cat['code'].documentCount()
     264          #print "TITLES: ", cat['title'].documentCount()
     265          results = list(cat.searchResults(code=(query, query)))#
     266          #title=(query, query)))
     267          hitlist = []
     268          results = Query().searchResults(
     269               Eq(('courses_catalog', 'code'), query))
     270          for result in results:
     271               hitlist.append(CourseQueryResultItem(result, view=self))
     272
     273          results = Query().searchResults(
     274               Text(('courses_catalog', 'title'), query))
     275         
     276          for result in results:
     277               hitlist.append(CourseQueryResultItem(result, view=self))
     278
     279          self.hitlist = hitlist
     280
    186281
    187282#
Note: See TracChangeset for help on using the changeset viewer.