source: WAeUP_SRP/trunk/skins/waeup_utilities/fill_session_in_course_results.py @ 16680

Last change on this file since 16680 was 5203, checked in by Henrik Bettermann, 14 years ago

fix session_id in fill_session_in_course_results.py

  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1## Script (Python) "fill_session"
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: fill_session_in_course_results.py 5203 2010-05-23 04:29:20Z 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',):
22    return
23
24
25import logging
26import DateTime
27logger = logging.getLogger('fill_session_in_course_results')
28from Products.AdvancedQuery import Eq, Between, Le,In
29
30course_results = context.course_results
31students = context.portal_url.getPortalObject().campus.students
32
33
34brains = course_results()
35total = len(brains)
36edited = 0
37for brain in brains:
38    #set_trace()
39    if not brain.session_id:
40        data = {}
41        data['key'] = brain.key
42       
43        if not students.hasObject(brain.student_id):
44            logger.info("no student %s" % student_id)
45            continue
46        student = getattr(students, brain.student_id)       
47        if not student.hasObject("study_course"):
48            logger.info("%s: no study_course" % brain.student_id)
49            continue
50        study_course = student.study_course
51        if not study_course.hasObject(brain.level_id):
52            logger.info("%s: no level %s" % (brain.student_id,brain.level_id))
53            continue
54        level_obj = getattr(study_course, brain.level_id)   
55        level_doc = level_obj.getContent()   
56        #set_trace()
57        session_id = level_doc.session
58        if len(session_id) == 2:
59            pass
60        elif len(session_id) == 9:
61            session_id = session_id[2:4]
62        if len(session_id) != 2:
63            logger.info("invalid session %s in level %s for student %s" %
64                        (session_id,brain.level_id,brain.student_id))       
65        data['session_id'] = session_id
66        course_results.modifyRecord(**data)
67        logger.info("%s: session %s filled" % (brain.key,session_id))
68        edited += 1
69    #else:
70    #    logger.info("%s: %s" % (brain.student_id,brain.session_id))
71       
72logger.info("edited %d course results of %s total" % (edited,total))
Note: See TracBrowser for help on using the repository browser.