[3113] | 1 | ## Script (Python) "changeCreditsInCourseResults" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
[3166] | 7 | ##parameters=course_id |
---|
[3113] | 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: changeCreditsInCourseResults.py 3166 2008-02-14 21:05:27Z henrik $ |
---|
| 11 | """ |
---|
| 12 | """ |
---|
| 13 | try: |
---|
| 14 | from Products.zdb import set_trace |
---|
| 15 | except: |
---|
| 16 | def set_trace(): |
---|
| 17 | pass |
---|
| 18 | |
---|
| 19 | mtool = context.portal_membership |
---|
| 20 | member = mtool.getAuthenticatedMember() |
---|
| 21 | if str(member) not in ('admin','joachim'): |
---|
| 22 | return |
---|
| 23 | |
---|
| 24 | import logging |
---|
| 25 | import DateTime |
---|
| 26 | logger = logging.getLogger('Skins.changeCreditsInCourseResults') |
---|
| 27 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 28 | aq_course_results = context.course_results.evalAdvancedQuery |
---|
| 29 | aq_courses_catalog = context.courses_catalog.evalAdvancedQuery |
---|
| 30 | |
---|
| 31 | request = context.REQUEST |
---|
| 32 | session = request.SESSION |
---|
| 33 | |
---|
| 34 | query = Eq('code',course_id) |
---|
| 35 | course_results = aq_course_results(query) |
---|
| 36 | edited = 0 |
---|
| 37 | wrong = 0 |
---|
| 38 | count = 0 |
---|
| 39 | commit_after = 50 |
---|
| 40 | course = context.courses_catalog.getRecordByKey(course_id) |
---|
| 41 | new_credits = course.credits |
---|
[3129] | 42 | #logger.info('started to change %d course_results credits from %s to %s' % |
---|
| 43 | # (len(course_results),old_credits,new_credits)) |
---|
[3113] | 44 | to_edit = [] |
---|
| 45 | for course_result in course_results: |
---|
| 46 | count += 1 |
---|
[3166] | 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 |
---|
[3113] | 53 | to_edit += course_result.key, |
---|
[3166] | 54 | logger.info('%d %s course results found, start editing credits to %s' % |
---|
| 55 | (len(course_results),course_id,new_credits)) |
---|
[3113] | 56 | for key in to_edit: |
---|
| 57 | context.course_results.modifyRecord(**{'key': key, 'credits': int(new_credits)}) |
---|
[3166] | 58 | logger.info('finished editing %d %s course results' % (count, course_id)) |
---|
[3113] | 59 | |
---|