source: WAeUP_SRP/branches/uli/skins/waeup_utilities/fixLevelForNewStudents.py @ 15131

Last change on this file since 15131 was 1593, checked in by uli, 18 years ago

Merged current trunk into uli-branch.

  • Property svn:keywords set to Id
File size: 3.3 KB
RevLine 
[1593]1## Script (Python) "fixLevelForNewStudents"
[1473]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"""
12list Students for ClearanceOfficers
13"""
[1485]14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
[1473]19
20request = context.REQUEST
21session = request.SESSION
22response = request.RESPONSE
23setheader = request.RESPONSE.setHeader
[1485]24import logging
[1593]25logger = logging.getLogger('Skins.fixLevelForNewStudents')
[1473]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')
[1490]49#res = aq_students(query)
50res = students_cat(level='100')
[1486]51#set_trace()
[1473]52count = 0
[1490]53count_full = 0
[1486]54commit_count = 0
[1593]55logger.info("Started for %s students" % len(res))
[1491]56to_change = {}
[1473]57for sbrain in res:
[1490]58    #count_full += 1
59    #rwrite("%s: %s %s %s <br />" % (count_full,sbrain.id,sbrain.entry_mode,sbrain.level))
[1484]60    student_obj = getattr(students,sbrain.id)
[1491]61    changed = False
[1473]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
[1491]66        changed = True
[1473]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":
[1491]72        changed = True
[1473]73        level = "200"
74    else:
75        level = "100"
[1491]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)
[1473]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,
[1485]89                                                        'current_verdict': 'N/A'})
[1473]90    count += 1
[1486]91    commit_count += 1
92    if commit_count > 1000:
93        context.waeup_tool.doCommit()
[1593]94        logger.info("Committing %s transactions, total %s" % (commit_count,count))
[1486]95        commit_count = 0
[1473]96    rwrite("%s: %s %s %s <br />" % (count,sbrain.id,entry_mode,level))
[1491]97for entry in to_change.keys():
98    students_cat.modifyRecord(**to_change[entry])
[1485]99rwrite("finished")
[1593]100logger.info("Finished  %s students" % count)
Note: See TracBrowser for help on using the repository browser.