[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 1392 2007-02-05 15:59:08Z henrik $ |
---|
| 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 | |
---|
| 36 | |
---|
| 37 | |
---|
[1387] | 38 | if str(member) not in ('admin','joachim'): |
---|
[1391] | 39 | return |
---|
[1387] | 40 | count = 0 |
---|
| 41 | lc = 1 |
---|
[1391] | 42 | lines = [] |
---|
[1387] | 43 | #from Products.zdb import set_trace;set_trace() |
---|
| 44 | res = scat() |
---|
| 45 | for sbrain in res: |
---|
[1392] | 46 | |
---|
| 47 | old_level = str(sbrain.level) |
---|
| 48 | |
---|
[1391] | 49 | if str(sbrain.level) == '100': |
---|
| 50 | ec = "new" |
---|
| 51 | else: |
---|
| 52 | ec = "nor" |
---|
[1387] | 53 | erg = context.results_import(matric_no=sbrain.matric_no) |
---|
| 54 | if erg and erg[0].Level: |
---|
| 55 | ec = "e" |
---|
| 56 | level = erg[0].Level |
---|
| 57 | for e in erg: |
---|
| 58 | ec = "E" |
---|
| 59 | if level != e.Level: |
---|
[1391] | 60 | ec = "%s:%s!=%s<br />\n" % (sbrain.matric_no,level,e.Level) |
---|
[1387] | 61 | level = "%d" % (int(level) + 100) |
---|
[1391] | 62 | |
---|
[1392] | 63 | context.students_catalog.modifyRecord(id = sbrain.id, level="") |
---|
[1391] | 64 | |
---|
[1387] | 65 | while True: |
---|
| 66 | student = getattr(students,sbrain.id,None) |
---|
[1388] | 67 | ec = "nos" |
---|
[1387] | 68 | if student is None: |
---|
| 69 | break |
---|
[1388] | 70 | ec = "nyr" |
---|
[1387] | 71 | study_course = getattr(student,"study_course", None) |
---|
| 72 | if study_course is None: |
---|
| 73 | break |
---|
[1391] | 74 | |
---|
[1392] | 75 | study_course.getContent().edit(mapping = {'current_level':level}) |
---|
[1391] | 76 | context.students_catalog.modifyRecord(id = sbrain.id, level=level) |
---|
| 77 | |
---|
[1388] | 78 | ec = "reg" |
---|
[1387] | 79 | break |
---|
[1392] | 80 | |
---|
[1391] | 81 | # rwrite(ec +"--"+ sbrain.id +"--"+ sbrain.matric_no +"--"+ old_level +"--"+ level +"<br />") |
---|
| 82 | |
---|
| 83 | lines.append('"%s","%s","%s","%s","%s"' % (ec,sbrain.id,sbrain.matric_no,old_level,level)) |
---|
[1388] | 84 | |
---|
[1391] | 85 | |
---|
[1388] | 86 | else: |
---|
[1391] | 87 | # rwrite(ec +"--"+ sbrain.id +"--"+ sbrain.matric_no + "<br />") |
---|
| 88 | lines.append('"%s","%s","%s","",""' % (ec,sbrain.id,sbrain.matric_no)) |
---|
| 89 | |
---|
[1388] | 90 | # count += 1 |
---|
| 91 | # if count > 60: |
---|
| 92 | # lc += 1 |
---|
| 93 | # rwrite("<br />\n%3d " % lc) |
---|
| 94 | # count = 0 |
---|
| 95 | |
---|
[1391] | 96 | #rwrite("<br />\n Done" ) |
---|
| 97 | |
---|
| 98 | setheader('Content-type','text/semicolon-seperated-values') |
---|
| 99 | setheader('Content-Disposition:', 'attachment; filename="fixLevelExport.csv"') |
---|
| 100 | setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past |
---|
| 101 | setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1 |
---|
| 102 | setheader('Cache-Control', 'post-check=0,pre-check=0') |
---|
| 103 | setheader('Pragma', 'no-cache') # HTTP/1.0 |
---|
| 104 | return '\n'.join(lines) |
---|
| 105 | |
---|