1 | ## Script (Python) "fixLevelForNewStudents" |
---|
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: fixLevelForNewStudents.py 1593 2007-03-19 18:57:54Z uli $ |
---|
11 | """ |
---|
12 | list Students for ClearanceOfficers |
---|
13 | """ |
---|
14 | try: |
---|
15 | from Products.zdb import set_trace |
---|
16 | except: |
---|
17 | def set_trace(): |
---|
18 | pass |
---|
19 | |
---|
20 | request = context.REQUEST |
---|
21 | session = request.SESSION |
---|
22 | response = request.RESPONSE |
---|
23 | setheader = request.RESPONSE.setHeader |
---|
24 | import logging |
---|
25 | logger = logging.getLogger('Skins.fixLevelForNewStudents') |
---|
26 | |
---|
27 | def rwrite(s): |
---|
28 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
29 | response.write(s) |
---|
30 | |
---|
31 | mtool = context.portal_membership |
---|
32 | member = mtool.getAuthenticatedMember() |
---|
33 | retcat = context.returning_import |
---|
34 | rcat = context.results_import |
---|
35 | students_cat = context.students_catalog |
---|
36 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
37 | aq_students = students_cat.evalAdvancedQuery |
---|
38 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
39 | students = context.portal_url.getPortalObject().campus.students |
---|
40 | |
---|
41 | count = 0 |
---|
42 | ##query = Eq('portal_type','Student') & In('review_state',('admitted', |
---|
43 | ## 'clearance_requested', |
---|
44 | ## 'cleared_and_validated', |
---|
45 | ## 'objection_raised', |
---|
46 | ## ) |
---|
47 | ##res = aq_portal(query) |
---|
48 | query = Eq('level','100') |
---|
49 | #res = aq_students(query) |
---|
50 | res = students_cat(level='100') |
---|
51 | #set_trace() |
---|
52 | count = 0 |
---|
53 | count_full = 0 |
---|
54 | commit_count = 0 |
---|
55 | logger.info("Started for %s students" % len(res)) |
---|
56 | to_change = {} |
---|
57 | for sbrain in res: |
---|
58 | #count_full += 1 |
---|
59 | #rwrite("%s: %s %s %s <br />" % (count_full,sbrain.id,sbrain.entry_mode,sbrain.level)) |
---|
60 | student_obj = getattr(students,sbrain.id) |
---|
61 | changed = False |
---|
62 | if sbrain.entry_mode == "": |
---|
63 | if not student_obj.hasObject('application'): |
---|
64 | rwrite("%s %s %s application not found <br />" % (sbrain.id,sbrain.entry_mode,level)) |
---|
65 | continue |
---|
66 | changed = True |
---|
67 | app_doc = student_obj.application.getContent() |
---|
68 | entry_mode = app_doc.entry_mode |
---|
69 | else: |
---|
70 | entry_mode = sbrain.entry_mode |
---|
71 | if entry_mode == "DE": |
---|
72 | changed = True |
---|
73 | level = "200" |
---|
74 | else: |
---|
75 | level = "100" |
---|
76 | if changed: |
---|
77 | d = {} |
---|
78 | d['id'] = sbrain.id |
---|
79 | d['level'] = level |
---|
80 | d['entry_mode'] = entry_mode |
---|
81 | to_change[sbrain.id] = d |
---|
82 | ## students_cat.modifyRecord(id=sbrain.id, |
---|
83 | ## level=level, |
---|
84 | ## entry_mode=entry_mode) |
---|
85 | if not student_obj.hasObject('study_course'): |
---|
86 | rwrite("%s %s %s study_course not found <br />" % (sbrain.id,sbrain.entry_mode,level)) |
---|
87 | continue |
---|
88 | student_obj.study_course.getContent().edit(mapping={'current_level': level, |
---|
89 | 'current_verdict': 'N/A'}) |
---|
90 | count += 1 |
---|
91 | commit_count += 1 |
---|
92 | if commit_count > 1000: |
---|
93 | context.waeup_tool.doCommit() |
---|
94 | logger.info("Committing %s transactions, total %s" % (commit_count,count)) |
---|
95 | commit_count = 0 |
---|
96 | rwrite("%s: %s %s %s <br />" % (count,sbrain.id,entry_mode,level)) |
---|
97 | for entry in to_change.keys(): |
---|
98 | students_cat.modifyRecord(**to_change[entry]) |
---|
99 | rwrite("finished") |
---|
100 | logger.info("Finished %s students" % count) |
---|