[3353] | 1 | ## Script (Python) "ti_507_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_507_resolve.py 3780 2008-11-21 09:26:51Z henrik $ |
---|
| 11 | """ |
---|
| 12 | """ |
---|
| 13 | try: |
---|
| 14 | from Products.zdb import set_trace |
---|
| 15 | except: |
---|
| 16 | def set_trace(): |
---|
| 17 | pass |
---|
| 18 | |
---|
| 19 | mtool = context.portal_membership |
---|
| 20 | member = mtool.getAuthenticatedMember() |
---|
| 21 | if str(member) not in ('admin','joachim'): |
---|
| 22 | return |
---|
| 23 | |
---|
| 24 | import logging |
---|
| 25 | import DateTime |
---|
| 26 | logger = logging.getLogger('Skins.ti_507_resolve') |
---|
| 27 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 28 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 29 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
| 30 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 31 | |
---|
| 32 | request = context.REQUEST |
---|
| 33 | session = request.SESSION |
---|
| 34 | response = request.RESPONSE |
---|
| 35 | setheader = request.RESPONSE.setHeader |
---|
| 36 | logger.info('start') |
---|
| 37 | count = 0 |
---|
| 38 | found = 0 |
---|
[3376] | 39 | commit_after = 1000 |
---|
[3353] | 40 | certificates = context.getCertificatesDict() |
---|
| 41 | students = context.students_catalog() |
---|
[3376] | 42 | wrong = {} |
---|
[3353] | 43 | missing_courses = [] |
---|
[3361] | 44 | wrong_modes = {} |
---|
[3365] | 45 | students_with_missing_courses = [] |
---|
[3353] | 46 | for student in students: |
---|
| 47 | count += 1 |
---|
[3368] | 48 | if student.mode and student.course: |
---|
[3353] | 49 | certificate = certificates.get(student.course,None) |
---|
| 50 | if certificate is None: |
---|
[3365] | 51 | students_with_missing_courses += student.id, |
---|
[3353] | 52 | if student.course not in missing_courses: |
---|
| 53 | missing_courses += student.course, |
---|
[3365] | 54 | #logger.info('missing course %s' % student.course) |
---|
[3353] | 55 | continue |
---|
[3368] | 56 | current_mode = student.mode |
---|
[3365] | 57 | study_mode = certificate.get('study_mode','xxx') |
---|
[3368] | 58 | if current_mode != study_mode: |
---|
| 59 | w_count = wrong_modes.get((current_mode,study_mode),0) |
---|
[3777] | 60 | #if w_count == 0: |
---|
| 61 | # logger.info('%s != %s' % (student.mode, |
---|
| 62 | # study_mode)) |
---|
[3361] | 63 | w_count += 1 |
---|
[3368] | 64 | wrong_modes[(current_mode,study_mode)] = w_count |
---|
[3376] | 65 | d = {} |
---|
| 66 | d['student_id'] = student.id |
---|
| 67 | d['current_mode'] = study_mode |
---|
| 68 | d['current_mode_old'] = current_mode |
---|
[3778] | 69 | d['study_course'] = student.course |
---|
| 70 | d['matric_no'] = student.matric_no |
---|
[3780] | 71 | d['entry_mode'] = student.entry_mode |
---|
[3376] | 72 | wrong[student.id] = d |
---|
[3777] | 73 | if (student.mode,study_mode) not in (('ume_ft', 'ug_ft'),('de_pt', 'ug_pt'),('de_ft', 'ug_ft')): |
---|
[3780] | 74 | logger.info("; %(student_id)s; %(matric_no)s ; %(study_course)s ; %(entry_mode)s ; %(current_mode_old)s ; %(current_mode)s" % d) |
---|
[3376] | 75 | # if wrong and not (len(wrong) % commit_after): |
---|
| 76 | # logger.info('found %d wrong of %d' % (len(wrong),count)) |
---|
[3361] | 77 | for k,v in wrong_modes.items(): |
---|
| 78 | logger.info('wrong mode %s counted %d' % (k,v)) |
---|
[3365] | 79 | logger.info('missing courses %s (%d counted)' % (', '.join(missing_courses),len(students_with_missing_courses))) |
---|
[3353] | 80 | logger.info('found %d wrong of %d' % (len(wrong),count)) |
---|
[3376] | 81 | count = 0 |
---|
[3777] | 82 | |
---|
| 83 | return |
---|
| 84 | |
---|
[3780] | 85 | # the following must not be done because I've changed get_from_doc_mode in WAeUPTables. The current_mode field |
---|
| 86 | # of the study_course object is no longer used |
---|
| 87 | |
---|
[3376] | 88 | for student_id,d in wrong.items(): |
---|
| 89 | #set_trace() |
---|
| 90 | try: |
---|
| 91 | getattr(getattr(students_folder,student_id),'study_course').getContent().edit(mapping=d) |
---|
| 92 | failed = False |
---|
| 93 | except: |
---|
| 94 | failed = True |
---|
| 95 | if failed: |
---|
| 96 | logger.info("%(student_id)s change failed") |
---|
| 97 | else: |
---|
| 98 | logger.info("%(student_id)s changed current_mode from %(current_mode_old)s to %(current_mode)s" % d) |
---|
| 99 | if count and not count % commit_after: |
---|
| 100 | context.waeup_tool.doCommit() |
---|
| 101 | logger.info("committing %d of total %d" % (commit_after,count)) |
---|
| 102 | count += 1 |
---|