[1672] | 1 | ## Script (Python) "getNewStudentStatistics" |
---|
| 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_182_resolve.py 1672 2007-04-07 16:31:30Z joachim $ |
---|
| 11 | """ |
---|
| 12 | resolve ticket #182 |
---|
| 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_182_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 intersect(m,n): |
---|
| 32 | return [i for i in m if i in n] |
---|
| 33 | |
---|
| 34 | def rwrite(s): |
---|
| 35 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 36 | response.write("%s<br>\n\r" % s) |
---|
| 37 | def getObject(outer,object): |
---|
| 38 | if outer.hasObject(object): |
---|
| 39 | return getattr(outer,object) |
---|
| 40 | return None |
---|
| 41 | try: |
---|
| 42 | from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp |
---|
| 43 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
| 44 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 45 | except: |
---|
| 46 | evalAdvancedQuery = None |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | #freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE')) |
---|
| 50 | #total_new = aq_students(freshquery) |
---|
| 51 | ##query = In('review_state',('cleared_and_validated', |
---|
| 52 | ## 'school_fee_paid', |
---|
| 53 | ## 'courses_registered', |
---|
| 54 | ## 'courses_validated')) |
---|
| 55 | ##cleared = aq_portal(query) |
---|
| 56 | ##rwrite("Cleared and beyond students: %d" % len(cleared)) |
---|
| 57 | ##cleared_ids = [s.getId for s in cleared] |
---|
| 58 | newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*') |
---|
| 59 | new_students = aq_portal(newquery) |
---|
| 60 | new_ids = [r.getPath().split('/')[-2] for r in new_students] |
---|
| 61 | rwrite("New students: %d" % len(new_ids)) |
---|
| 62 | #diff_new_cleared = [i for i in new_ids if i not in cleared_ids] |
---|
| 63 | #diff_cleared_new = [i for i in cleared_ids if i not in new_ids] |
---|
| 64 | ##special_states = ('admitted', |
---|
| 65 | ## 'clearance_pin_entered', |
---|
| 66 | ## 'clearance_requested', |
---|
| 67 | ## 'cleared_and_validated', |
---|
| 68 | ## 'objection_raised', |
---|
| 69 | ## ) |
---|
| 70 | ##special_query = In('review_state',special_states) |
---|
| 71 | ##special = aq_portal(special_query) |
---|
| 72 | ##special_ids = [s.getId for s in special] |
---|
| 73 | ##rwrite("New special students: %d" % len(special_ids)) |
---|
| 74 | admitted_query = Eq('review_state','admitted') |
---|
| 75 | admitted = aq_portal(admitted_query) |
---|
| 76 | admitted_ids = [s.getId for s in admitted] |
---|
| 77 | rwrite("Admitted students: %d" % len(admitted_ids)) |
---|
| 78 | ##faculties = context.portal_catalog(portal_type="Faculty") |
---|
| 79 | ##fac_ids = [f.getId for f in faculties] |
---|
| 80 | ##fac_query = In('faculty',fac_ids) |
---|
| 81 | ##faculties_students = aq_students(fac_query) |
---|
| 82 | ##faculties_student_ids = [s.id for s in faculties_students] |
---|
| 83 | ##set_trace() |
---|
| 84 | count = 0 |
---|
| 85 | for sid in admitted_ids: |
---|
| 86 | if sid not in new_ids: |
---|
| 87 | if not count: |
---|
| 88 | rwrite('Students with review_state admitted and jamb_reg_no not beginning with 6') |
---|
| 89 | count += 1 |
---|
| 90 | erg = context.students_catalog(id=sid) |
---|
| 91 | if not erg: |
---|
| 92 | set_trace() |
---|
| 93 | continue |
---|
| 94 | student = erg[0] |
---|
| 95 | dict = context.getFormattedStudentEntry(student) |
---|
| 96 | dict['count'] = count |
---|
| 97 | dict['review_state'] = 'admitted' |
---|
| 98 | rwrite('"%(count)d","%(id)s","%(name)s","%(jamb_reg_no)s","%(faculty)s","%(entry_mode)s,"%(review_state)s,"%(level)s",' % dict) |
---|
| 99 | |
---|
| 100 | ##retcount = 0 |
---|
| 101 | ##count = 0 |
---|
| 102 | ##newc = 0 |
---|
| 103 | ###set_trace() |
---|
| 104 | ##for student in cleared: |
---|
| 105 | ## erg = context.students_catalog(id=student.getId) |
---|
| 106 | ## if not erg: |
---|
| 107 | ## set_trace() |
---|
| 108 | ## continue |
---|
| 109 | ## if not erg[0].jamb_reg_no.startswith('6'): |
---|
| 110 | ## retcount += 1 |
---|
| 111 | ## continue |
---|
| 112 | ## newc += 1 |
---|
| 113 | ## if not student.getId in special_ids: |
---|
| 114 | ## count += 1 |
---|
| 115 | #### dict = context.getFormattedStudentEntry(student) |
---|
| 116 | #### dict['review_state'] = 'unknown' |
---|
| 117 | #### dict['count'] = count |
---|
| 118 | #### res = context.portal_catalog(portal_type='Student',id = student.getId) |
---|
| 119 | #### if res: |
---|
| 120 | #### rs = dict['review_state'] = res[0].review_state |
---|
| 121 | #### rwrite('"%(count)d","%(id)s","%(name)s","%(jamb_reg_no)s","%(matric_no)s","%(entry_mode)s,"%(level)s","%(review_state)s"' % dict) |
---|
| 122 | ##rwrite("Cleared not in special: %d" % count) |
---|
| 123 | ##rwrite("Returning students: %d" % retcount) |
---|
| 124 | ##rwrite("New cleared students: %d" % newc) |
---|
| 125 | rwrite("Finished") |
---|
| 126 | |
---|