source: WAeUP_SRP/trunk/skins/waeup_utilities/reindexCoursesCatalog.py @ 16651

Last change on this file since 16651 was 1567, checked in by Henrik Bettermann, 18 years ago

new logging format Part 2

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1## Script (Python) "reindexCourseCatalog"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=REQUEST
8##title=
9##
10# $Id: reindexCoursesCatalog.py 1567 2007-03-17 08:34:51Z henrik $
11"""
12list Students for ClearanceOfficers
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20request = context.REQUEST
21session = request.SESSION
22response = request.RESPONSE
23setheader = request.RESPONSE.setHeader
24import logging
25logger = logging.getLogger('Skins.reindexCourseCatalog')
26
27def rwrite(s):
28    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
29    response.write(s)
30
31mtool = context.portal_membership
32member = mtool.getAuthenticatedMember()
33#students_cat = context.students_catalog
34courses_cat = context.courses_catalog
35from Products.AdvancedQuery import Eq, Between, Le,In
36#aq_students = students_cat.evalAdvancedQuery
37aq_portal = context.portal_catalog.evalAdvancedQuery
38students = context.portal_url.getPortalObject().campus.students
39
40count = 0
41##query = Eq('portal_type','Student') & In('review_state',('admitted',
42##                                                         'clearance_requested',
43##                                                         'cleared_and_validated',
44##                                                         'objection_raised',
45##                                                         )
46##res = aq_portal(query)
47query = Eq('portal_type','Course')
48courses = aq_portal(query)
49#set_trace()
50count = 0
51count_full = 0
52commit_count = 0
53logger.info("Reindexing of courses_catalog started for %s courses" % len(courses))
54for course_brain in courses:
55    course_doc = course_brain.getObject().getContent()
56    d = {}
57    d['code'] = getattr(course_doc,'code')
58    d['credits'] = getattr(course_doc,'credits')
59    d['level'] = getattr(course_doc,'level')
60    d['passmark'] = getattr(course_doc,'passmark')
61    d['semester'] = getattr(course_doc,'semester')
62    d['title'] = getattr(course_doc,'title')
63    pl = course_brain.getPath().split('/')
64    d['faculty'] = pl[-4]
65    d['department'] = pl[-3]
66    try:
67        courses_cat.modifyRecord(**d)
68    except KeyError:
69        courses_cat.addRecord(**d)
70    count += 1
71    commit_count += 1
72    if commit_count > 1000:
73        context.waeup_tool.doCommit()
74        logger.info("Committing %s transactions, total %s" % (commit_count,count))
75        rwrite("%s: committed %s <br />" % (count,commit_count))
76        commit_count = 0
77rwrite("finished")
78logger.info("Reindexing finished (%s courses)" % count)
Note: See TracBrowser for help on using the repository browser.