| 1 | ## Script (Python) "ti_151_resolve" |
|---|
| 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: ti_151_resolve.py 1642 2007-03-26 20:10:15Z joachim $ |
|---|
| 11 | """ |
|---|
| 12 | resolve ticket #151 |
|---|
| 13 | """ |
|---|
| 14 | try: |
|---|
| 15 | from Products.zdb import set_trace |
|---|
| 16 | except: |
|---|
| 17 | def set_trace(): |
|---|
| 18 | pass |
|---|
| 19 | import logging |
|---|
| 20 | #>>>>>>>>>>>>>>>>< |
|---|
| 21 | logger = logging.getLogger('Skins.ti_151_resolve') |
|---|
| 22 | logger.info('already done on 26.3.07 by joachim') |
|---|
| 23 | return |
|---|
| 24 | #<<<<<<<<<<<<<<<<< |
|---|
| 25 | request = context.REQUEST |
|---|
| 26 | session = request.SESSION |
|---|
| 27 | response = request.RESPONSE |
|---|
| 28 | setheader = request.RESPONSE.setHeader |
|---|
| 29 | students = context.portal_url.getPortalObject().campus.students |
|---|
| 30 | #from string import Template |
|---|
| 31 | def rwrite(s): |
|---|
| 32 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
|---|
| 33 | response.write(s) |
|---|
| 34 | def getObject(outer,object): |
|---|
| 35 | if outer.hasObject(object): |
|---|
| 36 | return getattr(outer,object) |
|---|
| 37 | return None |
|---|
| 38 | |
|---|
| 39 | try: |
|---|
| 40 | from Products.AdvancedQuery import Eq, Between, Le,In |
|---|
| 41 | aq_students = context.students_catalog.evalAdvancedQuery |
|---|
| 42 | except: |
|---|
| 43 | evalAdvancedQuery = None |
|---|
| 44 | |
|---|
| 45 | students_cat = context.students_catalog |
|---|
| 46 | query = Eq('faculty','PSC') & Eq('department','PHY') & In('level',('300','400')) |
|---|
| 47 | brains = aq_students(query) |
|---|
| 48 | #brains = students_cat(faculty = 'PSC',department='PHY', level='400') |
|---|
| 49 | total = 0 |
|---|
| 50 | count_ok = 0 |
|---|
| 51 | count_nosc = 0 |
|---|
| 52 | count_nolevel = 0 |
|---|
| 53 | count_level = 0 |
|---|
| 54 | count_renamed = 0 |
|---|
| 55 | #set_trace() |
|---|
| 56 | #template = Template('"$count","$id","$course"') |
|---|
| 57 | to_rename = [] |
|---|
| 58 | for student in brains: |
|---|
| 59 | student_dict = {} |
|---|
| 60 | for field in students_cat.schema(): |
|---|
| 61 | student_dict[field] = getattr(student,field) |
|---|
| 62 | #s = template.substitute(student_dict,count=count,) |
|---|
| 63 | student_dict['total'] = total |
|---|
| 64 | while True: |
|---|
| 65 | if student.course == "BSCINP": |
|---|
| 66 | student_dict['message'] = "OK" |
|---|
| 67 | count_ok += 1 |
|---|
| 68 | student_dict['sp_count'] = count_ok |
|---|
| 69 | s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict |
|---|
| 70 | break |
|---|
| 71 | student_dict['message'] = "" |
|---|
| 72 | student_obj = getObject(students,student.id) |
|---|
| 73 | if student_obj is None: |
|---|
| 74 | student_dict['message'] = "No student object" |
|---|
| 75 | break |
|---|
| 76 | study_course_obj = getObject(student_obj,'study_course') |
|---|
| 77 | if study_course_obj is None: |
|---|
| 78 | student_dict['message'] = "No study_course object" |
|---|
| 79 | count_nosc += 1 |
|---|
| 80 | student_dict['sp_count'] = count_nosc |
|---|
| 81 | break |
|---|
| 82 | level_obj = getObject(student_obj,student.level) |
|---|
| 83 | if level_obj: |
|---|
| 84 | count_level += 1 |
|---|
| 85 | study_course.manage_delObjects((student.level,)) |
|---|
| 86 | student_dict['message'] = "Level deleted" |
|---|
| 87 | student_dict['sp_count'] = count_level |
|---|
| 88 | count_renamed += 1 |
|---|
| 89 | to_rename.append(student.id) |
|---|
| 90 | student_dict['sp_count'] = count_renamed |
|---|
| 91 | student_dict['message'] = student_dict['message'] + "renamed to BSCINP" |
|---|
| 92 | study_course_doc = study_course_obj.getContent() |
|---|
| 93 | study_course_obj.edit(mapping = {'study_course': "BSCINP"}) |
|---|
| 94 | total += 1 |
|---|
| 95 | s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict |
|---|
| 96 | rwrite("%s<br />\r\n" %s) |
|---|
| 97 | break |
|---|
| 98 | total += 1 |
|---|
| 99 | s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict |
|---|
| 100 | rwrite("%s<br />\r\n" %s) |
|---|
| 101 | for sid in to_rename: |
|---|
| 102 | students_cat.modifyRecord(id = sid,course="BSCINP") |
|---|
| 103 | sum = count_ok + count_nosc + count_nolevel + count_level |
|---|
| 104 | rwrite("total=%d,sum of below=%d,<br>\r\n correct study_course=%d<br>\r\n no study_course=%d<br>\r\n no level=%d<br>\r\n with level =%d,<br />\n Done" % |
|---|
| 105 | (total, |
|---|
| 106 | sum, |
|---|
| 107 | count_ok, |
|---|
| 108 | count_nosc, |
|---|
| 109 | count_nolevel, |
|---|
| 110 | count_level) |
|---|
| 111 | ) |
|---|
| 112 | |
|---|
| 113 | logger.info("total=%d,sum=%d,ok=%d,no study_course=%d,no level=%d,with level =%d,\n Done" % |
|---|
| 114 | (total,sum,count_ok,count_nosc,count_nolevel,count_level)) |
|---|