source: WAeUP_SRP/base/skins/waeup_utilities/moveCourseResults.py @ 2535

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

new deadline

layout and schema should be called application (like the other layouts)

  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[2502]1## Script (Python) "ti_385_resolve"
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: moveCourseResults.py 2516 2007-11-03 18:59:28Z 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.moveCourseResults')
28from Products.AdvancedQuery import Eq, Between, Le,In
[2507]29aq_results = context.course_results.evalAdvancedQuery
[2502]30aq_students = context.students_catalog.evalAdvancedQuery
31students = context.portal_url.getPortalObject().campus.students
32request = context.REQUEST
33session = request.SESSION
34response = request.RESPONSE
35setheader = request.RESPONSE.setHeader
[2508]36#def rwrite(s):
37#    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
38#    response.write("%s<br>\n\r" % s)
[2502]39
40#logger.info('')
41
[2513]42brains = aq_students(In('review_state',('courses_registered','courses_validated')))
[2502]43total = len(brains)
44logger.info("found %d students" % (total))
45count = 0
46moved = 0
47cocount = 0
[2513]48commit_after = 20
[2514]49moved_sids = context.course_results.uniqueValuesFor('student_id')
[2502]50for brain in brains:
[2516]51    count += 1
[2514]52    if brain.id in moved_sids:
[2507]53        continue
[2502]54    try:
55        study_level = getattr(getattr(getattr(students,brain.id),
56                                  "study_course")
57                          ,brain.level)
58        results = study_level.objectIds()
59    except:
[2508]60        #rwrite('not found %s/study_course/%s' % (brain.id,brain.level))
[2502]61        continue
62    if not results:
[2513]63        continue
[2508]64        #rwrite('no result objects in %s/study_course/%s' % (brain.id,brain.level))
[2502]65    else:
[2513]66        #logger.info("moving  results of student %s" % (brain.id))
[2502]67        context.course_results.moveResultsHere(study_level,brain.id)
68        moved += 1
[2516]69        logger.info("moved results of student %s" % (brain.id))
[2513]70        if moved and not moved % commit_after:
71            context.waeup_tool.doCommit()
72            logger.info("Committing %s transactions, total %s" % (commit_after,count))
[2514]73            cocount += 1
74            if cocount > 2:
75                break
[2513]76
77msg = "finished moving results of %d students" % (moved)
[2502]78logger.info(msg)
[2508]79#rwrite(msg)
[2507]80
[2508]81
Note: See TracBrowser for help on using the repository browser.