source: WAeUP_SRP/trunk/skins/waeup_utilities/changeCreditsInCourseResults.py @ 8794

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

simplify

old_credits is not always being provided by CRPU staff.

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1## Script (Python) "changeCreditsInCourseResults"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=course_id
8##title=
9##
10# $Id: changeCreditsInCourseResults.py 3166 2008-02-14 21:05:27Z 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
24import logging
25import DateTime
26logger = logging.getLogger('Skins.changeCreditsInCourseResults')
27from Products.AdvancedQuery import Eq, Between, Le,In
28aq_course_results = context.course_results.evalAdvancedQuery
29aq_courses_catalog = context.courses_catalog.evalAdvancedQuery
30
31request = context.REQUEST
32session = request.SESSION
33
34query = Eq('code',course_id)
35course_results = aq_course_results(query)
36edited = 0
37wrong = 0
38count = 0
39commit_after = 50
40course = context.courses_catalog.getRecordByKey(course_id)
41new_credits = course.credits
42#logger.info('started to change %d course_results credits from %s to %s' %
43#            (len(course_results),old_credits,new_credits))
44to_edit = []
45for course_result in course_results:
46    count += 1
47    #if int(course_result.credits) != int(old_credits):
48    #    logger.info("%s: credits %s does not match %s" % (course_result.key,
49    #                                                     course_result.credits,
50    #                                                     old_credits))
51    #    wrong += 1
52    #    continue
53    to_edit += course_result.key,
54logger.info('%d %s course results found, start editing credits to %s' %
55            (len(course_results),course_id,new_credits))
56for key in to_edit:
57    context.course_results.modifyRecord(**{'key': key, 'credits': int(new_credits)})
58logger.info('finished editing %d %s course results' % (count, course_id))
59
Note: See TracBrowser for help on using the repository browser.