1 | ## Script (Python) "reindex_entry_mode" |
---|
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: reindexStudentsCatFacultyDepartment.py 1478 2007-02-23 15:09:15Z joachim $ |
---|
11 | """ |
---|
12 | reindex students_catalog entry_mode index |
---|
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 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
25 | |
---|
26 | def rwrite(s): |
---|
27 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
28 | response.write(s) |
---|
29 | |
---|
30 | students_cat = context.students_catalog |
---|
31 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
32 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
33 | |
---|
34 | students = students_cat() |
---|
35 | count = 0 |
---|
36 | certificates = {} |
---|
37 | d = {} |
---|
38 | d['faculty'] = 'n/a' |
---|
39 | d['department'] = 'n/a' |
---|
40 | certificates['na'] = d |
---|
41 | count = 0 |
---|
42 | ch_count = 0 |
---|
43 | to_delete = [] |
---|
44 | for student in students: |
---|
45 | sc_found = False |
---|
46 | student_found = False |
---|
47 | changed = False |
---|
48 | if students_folder.hasObject(student.id): |
---|
49 | student_found = True |
---|
50 | student_obj = getattr(students_folder,student.id) |
---|
51 | if student_obj.hasObject('study_course'): |
---|
52 | sc = getattr(student_obj,'study_course') |
---|
53 | cert_id = sc.getContent().study_course |
---|
54 | if certificates.has_key(cert_id): |
---|
55 | d = certificates[cert_id] |
---|
56 | else: |
---|
57 | query = Eq('portal_type','Certificate') &\ |
---|
58 | Eq('id',cert_id) |
---|
59 | #set_trace() |
---|
60 | cert_brain = aq_portal(query)[0] |
---|
61 | d = {} |
---|
62 | d['faculty'] = cert_brain.getPath().split('/')[-4] |
---|
63 | d['department'] = cert_brain.getPath().split('/')[-3] |
---|
64 | certificates[cert_id] = d |
---|
65 | sc_found = True |
---|
66 | if student.faculty != d['faculty'] or student.department != d['department']: |
---|
67 | ch_count += 1 |
---|
68 | changed = True |
---|
69 | d['id'] = student.id |
---|
70 | students_cat.modifyRecord(**d) |
---|
71 | else: |
---|
72 | d = certificates['na'] |
---|
73 | else: |
---|
74 | d = certificates['na'] |
---|
75 | to_delete.append(student.id) |
---|
76 | count +=1 |
---|
77 | s = '"%s ","%s","%s","%s","%s","%s","%s","%s"' % (count,student_found,sc_found, |
---|
78 | changed,ch_count, |
---|
79 | student.id, |
---|
80 | d['faculty'], |
---|
81 | d['department'], |
---|
82 | ) |
---|
83 | rwrite("%s<br />" %s) |
---|
84 | |
---|
85 | #setheader('Content-type','text/semicolon-seperated-values') |
---|
86 | #setheader('Content-Disposition:', 'attachment; filename="fixLevelExport.csv"') |
---|
87 | #setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past |
---|
88 | #setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1 |
---|
89 | #setheader('Cache-Control', 'post-check=0,pre-check=0') |
---|
90 | #setheader('Pragma', 'no-cache') # HTTP/1.0 |
---|
91 | #return '\n'.join(lines) |
---|
92 | |
---|
93 | rwrite("<br />\n Done" ) |
---|
94 | |
---|