source: WAeUP_SRP/trunk/skins/waeup_utilities/fixLevelForNewStudents.py @ 17952

Last change on this file since 17952 was 1567, checked in by Henrik Bettermann, 18 years ago

new logging format Part 2

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
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 1567 2007-03-17 08:34:51Z henrik $
11"""
12list Students for ClearanceOfficers
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20request = context.REQUEST
21session = request.SESSION
22response = request.RESPONSE
23setheader = request.RESPONSE.setHeader
24import logging
25logger = logging.getLogger('Skins.fixLevelForNewStudents')
26
27def rwrite(s):
28    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
29    response.write(s)
30
31mtool = context.portal_membership
32member = mtool.getAuthenticatedMember()
33retcat = context.returning_import
34rcat = context.results_import
35students_cat = context.students_catalog
36from Products.AdvancedQuery import Eq, Between, Le,In
37aq_students = students_cat.evalAdvancedQuery
38aq_portal = context.portal_catalog.evalAdvancedQuery
39students = context.portal_url.getPortalObject().campus.students
40
41count = 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)
48query = Eq('level','100')
49#res = aq_students(query)
50res = students_cat(level='100')
51#set_trace()
52count = 0
53count_full = 0
54commit_count = 0
55logger.info("Started for %s students" % len(res))
56to_change = {}
57for 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))
97for entry in to_change.keys():
98    students_cat.modifyRecord(**to_change[entry])
99rwrite("finished")
100logger.info("Finished  %s students" % count)
Note: See TracBrowser for help on using the repository browser.