source: WAeUP_SRP/trunk/skins/waeup_utilities/purgeCourseResultsObjects.py @ 10692

Last change on this file since 10692 was 3206, checked in by Henrik Bettermann, 17 years ago

2 old fixes (in custom)

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1## Script (Python) "purgeCourseResultsObjects"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: purgeCourseResultsObjects.py 3206 2008-02-23 22:59:10Z henrik $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21if str(member) not in ('admin','joachim'):
22    return
23
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.purgeCourseResultsObjects')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_results = context.course_results.evalAdvancedQuery
30aq_portal = context.portal_catalog_real.evalAdvancedQuery
31#aq_students = context.students_catalog.evalAdvancedQuery
32students = context.portal_url.getPortalObject().campus.students
33request = context.REQUEST
34session = request.SESSION
35response = request.RESPONSE
36setheader = request.RESPONSE.setHeader
37
38results = aq_portal(Eq('portal_type','StudentCourseResult'))
39total = len(results)
40logger.info("found %d course result objects" % (total))
41count = 0
42moved = 0
43cocount = 0
44commit_after = 20
45current_student_id = ''
46current_level_id = ''
47to_move = []
48for result in results:
49    count += 1
50    pl = result.getPath().split('/')
51    student_id = pl[-4]
52    level_id = pl[-2]
53    if student_id != current_student_id:
54        if current_student_id:
55            to_move += (current_student_id,current_level_id),
56        current_student_id = student_id
57        current_level_id = level_id
58    elif level_id != current_level_id:
59        to_move += (current_student_id,current_level_id),
60        current_level_id = level_id
61for student_id,level_id in to_move:
62    try:
63        study_level = getattr(getattr(getattr(students,student_id),
64                                      "study_course")
65                              ,level_id)
66    except:
67        logger.info('%s level %s not found' % (student_id,level_id))
68        continue
69    context.course_results.moveResultsHere(study_level,student_id)
70    moved += 1
71    logger.info("moved results of student %s" % (student_id))
72    if moved and not moved % commit_after:
73        context.waeup_tool.doCommit()
74        logger.info("Committing %s transactions, total %s" % (commit_after,len(to_move)))
75        # cocount += 1
76        # if cocount > 2:
77        #     break
78msg = "finished moving results of %d students" % (moved)
79logger.info(msg)
80#rwrite(msg)
81
82
Note: See TracBrowser for help on using the repository browser.