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 1596 2007-03-19 21:45:44Z joachim $ |
---|
11 | """ |
---|
12 | list Students for ClearanceOfficers |
---|
13 | """ |
---|
14 | try: |
---|
15 | from Products.zdb import set_trace |
---|
16 | except: |
---|
17 | def set_trace(): |
---|
18 | pass |
---|
19 | |
---|
20 | request = context.REQUEST |
---|
21 | session = request.SESSION |
---|
22 | response = request.RESPONSE |
---|
23 | setheader = request.RESPONSE.setHeader |
---|
24 | import logging |
---|
25 | logger = logging.getLogger('Skins.reindexCourseCatalog') |
---|
26 | |
---|
27 | def rwrite(s): |
---|
28 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
29 | response.write(s) |
---|
30 | |
---|
31 | mtool = context.portal_membership |
---|
32 | member = mtool.getAuthenticatedMember() |
---|
33 | #students_cat = context.students_catalog |
---|
34 | courses_cat = context.courses_catalog |
---|
35 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
36 | #aq_students = students_cat.evalAdvancedQuery |
---|
37 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
38 | students = context.portal_url.getPortalObject().campus.students |
---|
39 | |
---|
40 | count = 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) |
---|
47 | query = Eq('portal_type','Course') |
---|
48 | courses = aq_portal(query) |
---|
49 | #set_trace() |
---|
50 | count = 0 |
---|
51 | count_full = 0 |
---|
52 | commit_count = 0 |
---|
53 | logger.info("Reindexing of courses_catalog started for %s courses" % len(courses)) |
---|
54 | for 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 |
---|
77 | rwrite("finished") |
---|
78 | logger.info("Reindexing finished (%s courses)" % count) |
---|