source: WAeUP_SRP/trunk/skins/waeup_utilities/reindexEndLevel.py @ 8500

Last change on this file since 8500 was 3058, checked in by joachim, 17 years ago

implement reindexEndLevel

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1## Script (Python) "reindexEndLevel"
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: reindexEndLevel.py 3058 2008-01-28 18:04:29Z joachim $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19
20mtool = context.portal_membership
21member = mtool.getAuthenticatedMember()
22
23import logging
24import DateTime
25logger = logging.getLogger('Skins.reindexEndLevel')
26from Products.AdvancedQuery import Eq, Between, Le,In
27#aq_portal = context.portal_catalog_real.evalAdvancedQuery
28aq_students = context.students_catalog.evalAdvancedQuery
29#students_folder = context.portal_url.getPortalObject().campus.students
30
31request = context.REQUEST
32session = request.SESSION
33student_records = context.students_catalog()
34total = len(student_records)
35logger.info("found %d students" % total)
36count = 1
37no_end_level = no_course = 1
38commit_after = 1000
39logger.info('started to reindex end_level for %d records in students_catalog' % total)
40certificate_dict = context.students_catalog.fill_certificates_dict()
41logger.info('filled certificate_dict')
42records_to_change = []
43for student_record in student_records:
44    # skip record without lga value
45    if not count % commit_after:
46        logger.info("found %d of %d sofar" % (len(records_to_change),count))
47        count += 1
48    if not student_record.course:
49        #logger.info("%d: %s course is empty" % (no_course,student_record.id))
50        no_course += 1
51        continue
52    if student_record.end_level and student_record.end_level == certificate_dict[student_record.course]['end_level']:
53        continue
54    elif not certificate_dict[student_record.course]['end_level']:
55        logger.info("%s: no end_level for course %s faculty %s department %s" % (student_record.id,
56                                                                                student_record.course,
57                                                                                student_record.faculty,
58                                                                                student_record.department))
59        no_end_level +=1
60        continue
61    records_to_change += (student_record,certificate_dict[student_record.course]['end_level']),
62for record,end_level in records_to_change:
63    logger.info("modified %s end_level from %s to %s" % (record.id,record.end_level,end_level))
64    context.students_catalog.modifyRecord(id = record.id,
65                                          record=record,end_level=end_level)
66logger.info('found %d certificates with empty end_level' % (no_end_level - 1))
67logger.info('found %d students with no course' % (no_course - 1))
68logger.info('corrected %d students with wrong end_level' % len(records_to_change))
Note: See TracBrowser for help on using the repository browser.