1 | """Cataloging components for WAeUP SIRP access-codes. |
---|
2 | """ |
---|
3 | import grok |
---|
4 | from datetime import datetime |
---|
5 | from hurry.query import Between |
---|
6 | from waeup.sirp.interfaces import IUniversity |
---|
7 | from waeup.sirp.accesscodes.interfaces import IAccessCode |
---|
8 | |
---|
9 | ac_cat_name = ('accesscode_catalog', 'name') |
---|
10 | ac_cat_invalidated = ('accesscode_catalog', 'invalidated') |
---|
11 | |
---|
12 | class 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 | |
---|
25 | def 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 | |
---|
35 | def invalidated_num(batch_prefix, batch_num): |
---|
36 | """Get number of invalidated entries in batch. |
---|
37 | """ |
---|
38 | return len(search_invalidated(batch_prefix, batch_num)) |
---|