source: main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/catalog.py @ 5114

Last change on this file since 5114 was 5096, checked in by uli, 15 years ago

Add cataloging components for search access-codes in WAeUP SIRP.

File size: 1.3 KB
Line 
1"""Cataloging components for WAeUP SIRP access-codes.
2"""
3import grok
4from datetime import datetime
5from hurry.query import Between
6from waeup.sirp.interfaces import IUniversity
7from waeup.sirp.accesscodes.interfaces import IAccessCode
8
9ac_cat_name = ('accesscode_catalog', 'name')
10ac_cat_invalidated = ('accesscode_catalog', 'invalidated')
11
12class AccessCodeCatalog(grok.Indexes):
13     """The accesscode catalog.
14     """
15     grok.site(IUniversity)
16     grok.name('accesscode_catalog')
17     grok.context(IAccessCode)
18
19     # We want to search for ACs by text and as attributes.
20     text = grok.index.Text(attribute='representation')
21     name = grok.index.Field(attribute='representation')
22     invalidated = grok.index.Field(attribute='invalidation_date')
23     student_id = grok.index.Field(attribute='student_id')
24
25def search_invalidated(batch_prefix, batch_num):
26     """Get set of ACs in batch already invalidated.
27     """
28     start = '%s-%s-' % (batch_prefix, batch_num)
29     end = '%s-%s-9999999999' % (batch_prefix, batch_num)
30     query = Between(
31          ac_cat_invalidated, datetime(1, 1, 1), None) & Between(
32          ac_cat_name, start, end)
33     return query.apply()
34
35def invalidated_num(batch_prefix, batch_num):
36     """Get number of invalidated entries in batch.
37     """
38     return len(search_invalidated(batch_prefix, batch_num))
Note: See TracBrowser for help on using the repository browser.