1 | ## Script (Python) "search_pins" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=REQUEST |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: fixLevel.py 1250 2007-01-09 17:19:20Z joachim $ |
---|
11 | """ |
---|
12 | list Students for ClearanceOfficers |
---|
13 | """ |
---|
14 | |
---|
15 | request = REQUEST |
---|
16 | wftool = context.portal_workflow |
---|
17 | mtool = context.portal_membership |
---|
18 | member = mtool.getAuthenticatedMember() |
---|
19 | roles = member.getRolesInContext(context) |
---|
20 | retcat = context.returning_import |
---|
21 | rcat = context.results_import |
---|
22 | scat = context.students_catalog |
---|
23 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
24 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
25 | |
---|
26 | if str(member) not in ('admin','joachim'): |
---|
27 | return |
---|
28 | count = 0 |
---|
29 | #from Products.zdb import set_trace;set_trace() |
---|
30 | values = scat.uniqueValuesFor('level') |
---|
31 | #query = ~ In("level",('100', '200', '300', '400', '500', '600')) |
---|
32 | query = In("level",('',)) |
---|
33 | res = aq_students(query) |
---|
34 | #from Products.zdb import set_trace;set_trace() |
---|
35 | modified = [] |
---|
36 | modified.append("%d to change" % len(res)) |
---|
37 | list = [] |
---|
38 | dbrains = {} |
---|
39 | for sbrain in res: |
---|
40 | list.append((sbrain.id,sbrain.matric_no,sbrain.course)) |
---|
41 | for id,m,c in list: |
---|
42 | erg = context.results_import(matric_no=m) |
---|
43 | if erg and erg[0].Level: |
---|
44 | context.students_catalog.modifyRecord(id = id, level=erg[0].Level) |
---|
45 | modified.append("%s, %s" % (id,m)) |
---|
46 | else: |
---|
47 | pres = context.portal_catalog(id=sbrain.id) |
---|
48 | if not pres: |
---|
49 | modified.append("no results for %s, %s" % (id,m)) |
---|
50 | continue |
---|
51 | review_state = pres[0].review_state |
---|
52 | if review_state not in ('admitted', |
---|
53 | 'clearance_pin_entered', |
---|
54 | 'clearance_requested', |
---|
55 | 'cleared_and_validated', |
---|
56 | ): |
---|
57 | modified.append("no new student %s" % (id)) |
---|
58 | continue |
---|
59 | cres = context.portal_catalog(id = c) |
---|
60 | if not cres: |
---|
61 | modified.append("no certificate %s for %s" % (id,c)) |
---|
62 | cert_doc = cres[0].getObject().getContent() |
---|
63 | level = getattr(cert_doc,'start_level',None) |
---|
64 | if level is None: |
---|
65 | modified.append("no start_level in certificate %s for %s" % (id,c)) |
---|
66 | context.students_catalog.modifyRecord(id=id, level=level) |
---|
67 | modified.append("%s, %s" % (id,c)) |
---|
68 | |
---|
69 | return '\n'.join(modified) |
---|