[1387] | 1 | ## Script (Python) "search_pins" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
[1391] | 7 | ##parameters= |
---|
[1387] | 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: fixLevelFromResults.py 1401 2007-02-08 18:08:38Z joachim $ |
---|
| 11 | """ |
---|
| 12 | list Students for ClearanceOfficers |
---|
| 13 | """ |
---|
| 14 | |
---|
| 15 | request = context.REQUEST |
---|
| 16 | session = request.SESSION |
---|
| 17 | response = request.RESPONSE |
---|
[1391] | 18 | setheader = request.RESPONSE.setHeader |
---|
| 19 | |
---|
| 20 | #def rwrite(s): |
---|
| 21 | # response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 22 | # response.write(s) |
---|
| 23 | |
---|
[1387] | 24 | wftool = context.portal_workflow |
---|
| 25 | mtool = context.portal_membership |
---|
| 26 | member = mtool.getAuthenticatedMember() |
---|
| 27 | roles = member.getRolesInContext(context) |
---|
| 28 | retcat = context.returning_import |
---|
| 29 | rcat = context.results_import |
---|
| 30 | scat = context.students_catalog |
---|
| 31 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 32 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 33 | students = context.portal_url.getPortalObject().campus.students |
---|
| 34 | |
---|
[1391] | 35 | |
---|
[1387] | 36 | if str(member) not in ('admin','joachim'): |
---|
[1391] | 37 | return |
---|
[1387] | 38 | count = 0 |
---|
[1401] | 39 | line_count = 0 |
---|
[1391] | 40 | lines = [] |
---|
[1387] | 41 | #from Products.zdb import set_trace;set_trace() |
---|
| 42 | res = scat() |
---|
| 43 | for sbrain in res: |
---|
[1392] | 44 | old_level = str(sbrain.level) |
---|
[1391] | 45 | if str(sbrain.level) == '100': |
---|
| 46 | ec = "new" |
---|
| 47 | else: |
---|
| 48 | ec = "nor" |
---|
[1387] | 49 | erg = context.results_import(matric_no=sbrain.matric_no) |
---|
[1401] | 50 | lc = 'u' |
---|
[1387] | 51 | if erg and erg[0].Level: |
---|
[1401] | 52 | lc = "e" # code for level status u = unset |
---|
[1387] | 53 | level = erg[0].Level |
---|
[1401] | 54 | everdict = erg[0].Verdict |
---|
| 55 | lnr = context.getLevelFromResultsCosCode(erg) |
---|
| 56 | if lnr == 0: |
---|
| 57 | lc = "-" |
---|
| 58 | if "%d00" % lnr != level: |
---|
| 59 | lc = "!" |
---|
| 60 | verdict,elegible = context.getVerdict(everdict) |
---|
| 61 | if elegible: |
---|
| 62 | lc = "+" |
---|
| 63 | level = "%d00" % (lnr + 1) |
---|
| 64 | context.students_catalog.modifyRecord(id = sbrain.id, |
---|
| 65 | level="", |
---|
| 66 | verdict = "") |
---|
[1387] | 67 | while True: |
---|
| 68 | student = getattr(students,sbrain.id,None) |
---|
[1388] | 69 | ec = "nos" |
---|
[1387] | 70 | if student is None: |
---|
| 71 | break |
---|
[1388] | 72 | ec = "nyr" |
---|
[1387] | 73 | study_course = getattr(student,"study_course", None) |
---|
| 74 | if study_course is None: |
---|
| 75 | break |
---|
[1401] | 76 | study_course.getContent().edit(mapping = {'current_level':level, |
---|
| 77 | 'current_verdict':verdict}) |
---|
| 78 | context.students_catalog.modifyRecord(id = sbrain.id, |
---|
| 79 | level=level, |
---|
| 80 | verdict=verdict) |
---|
[1388] | 81 | ec = "reg" |
---|
[1387] | 82 | break |
---|
[1392] | 83 | |
---|
[1391] | 84 | # rwrite(ec +"--"+ sbrain.id +"--"+ sbrain.matric_no +"--"+ old_level +"--"+ level +"<br />") |
---|
| 85 | |
---|
[1401] | 86 | lines.append('"%s %s","%s","%s","%s","%s","%s","%s"' % (lc,ec, |
---|
| 87 | sbrain.id, |
---|
| 88 | sbrain.matric_no, |
---|
| 89 | old_level, |
---|
| 90 | level, |
---|
| 91 | everdict, |
---|
| 92 | verdict)) |
---|
[1388] | 93 | |
---|
[1391] | 94 | |
---|
[1388] | 95 | else: |
---|
[1391] | 96 | # rwrite(ec +"--"+ sbrain.id +"--"+ sbrain.matric_no + "<br />") |
---|
| 97 | lines.append('"%s","%s","%s","",""' % (ec,sbrain.id,sbrain.matric_no)) |
---|
| 98 | |
---|
[1388] | 99 | # count += 1 |
---|
| 100 | # if count > 60: |
---|
[1401] | 101 | # line_count += 1 |
---|
| 102 | # rwrite("<br />\n%3d " % line_count) |
---|
[1388] | 103 | # count = 0 |
---|
| 104 | |
---|
[1391] | 105 | #rwrite("<br />\n Done" ) |
---|
| 106 | |
---|
| 107 | setheader('Content-type','text/semicolon-seperated-values') |
---|
| 108 | setheader('Content-Disposition:', 'attachment; filename="fixLevelExport.csv"') |
---|
| 109 | setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past |
---|
| 110 | setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1 |
---|
| 111 | setheader('Cache-Control', 'post-check=0,pre-check=0') |
---|
| 112 | setheader('Pragma', 'no-cache') # HTTP/1.0 |
---|
| 113 | return '\n'.join(lines) |
---|
| 114 | |
---|