Changeset 6786 for main/waeup.sirp
- Timestamp:
- 18 Sep 2011, 00:04:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/catalog.py
r6778 r6786 5 5 from hurry.query import Eq, Text 6 6 from hurry.query.query import Query 7 from zope.index.text.parsetree import ParseError 7 from zope.catalog.interfaces import ICatalog 8 from zope.component import queryUtility 8 9 from waeup.sirp.interfaces import IUniversity, IQueryResultItem 9 10 from waeup.sirp.students.interfaces import IStudent … … 26 27 27 28 title = u'Student Query Item' 28 description = u'Some student sfound in a search'29 description = u'Some student found in a search' 29 30 30 31 def __init__(self, context, view): … … 39 40 def search(query=None, searchtype=None, view=None): 40 41 hitlist = [] 41 #if not query:42 # view.flash('Empty search string.')43 # return44 42 if searchtype in ('name',): 45 43 results = Query().searchResults( … … 48 46 # Temporary solution to display all students added 49 47 if query == '*': 50 from zope.component import queryUtility51 from zope.catalog.interfaces import ICatalog52 48 cat = queryUtility(ICatalog, name='students_catalog') 53 49 results = cat.searchResults(student_id=(None, None)) … … 58 54 hitlist.append(StudentQueryResultItem(result, view=view)) 59 55 return hitlist 56 57 class SimpleFieldSearch(object): 58 """A programmatic (no UI required) search. 59 60 Looks up a given field attribute of the students catalog for a 61 single value. So normally you would call an instance of this 62 search like this: 63 64 >>> SimpleFieldSearch()(reg_number='somevalue') 65 66 """ 67 catalog_name = 'students_catalog' 68 def __call__(self, **kw): 69 """Search students catalog programmatically. 70 """ 71 if len(kw) != 1: 72 raise ValueError('must give exactly one index name to search') 73 cat = queryUtility(ICatalog, name=self.catalog_name) 74 index_name, query_term = kw.items()[0] 75 results = cat.searchResults(index_name=(query_term, query_term)) 76 return results 77 78 #: an instance of `SimpleFieldSearch` looking up students catalog. 79 simple_search = SimpleFieldSearch()
Note: See TracChangeset for help on using the changeset viewer.