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 | """ |
---|
13 | try: |
---|
14 | from Products.zdb import set_trace |
---|
15 | except: |
---|
16 | def set_trace(): |
---|
17 | pass |
---|
18 | |
---|
19 | |
---|
20 | mtool = context.portal_membership |
---|
21 | member = mtool.getAuthenticatedMember() |
---|
22 | |
---|
23 | import logging |
---|
24 | import DateTime |
---|
25 | logger = logging.getLogger('Skins.reindexEndLevel') |
---|
26 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
27 | #aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
28 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
29 | #students_folder = context.portal_url.getPortalObject().campus.students |
---|
30 | |
---|
31 | request = context.REQUEST |
---|
32 | session = request.SESSION |
---|
33 | student_records = context.students_catalog() |
---|
34 | total = len(student_records) |
---|
35 | logger.info("found %d students" % total) |
---|
36 | count = 1 |
---|
37 | no_end_level = no_course = 1 |
---|
38 | commit_after = 1000 |
---|
39 | logger.info('started to reindex end_level for %d records in students_catalog' % total) |
---|
40 | certificate_dict = context.students_catalog.fill_certificates_dict() |
---|
41 | logger.info('filled certificate_dict') |
---|
42 | records_to_change = [] |
---|
43 | for 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']), |
---|
62 | for 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) |
---|
66 | logger.info('found %d certificates with empty end_level' % (no_end_level - 1)) |
---|
67 | logger.info('found %d students with no course' % (no_course - 1)) |
---|
68 | logger.info('corrected %d students with wrong end_level' % len(records_to_change)) |
---|