[1592] | 1 | ## Script (Python) "refresh_level" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
[1590] | 7 | ##parameters=REQUEST=None, student=None, action_after_reject=None, action_after_validate=None |
---|
[1510] | 8 | # $Id: refresh_level.py 2040 2007-07-20 11:05:34Z joachim $ |
---|
| 9 | """ |
---|
| 10 | process the Application Form |
---|
| 11 | return html renderer + psm |
---|
| 12 | """ |
---|
| 13 | request = context.REQUEST |
---|
| 14 | import DateTime,logging |
---|
| 15 | try: |
---|
| 16 | from Products.zdb import set_trace |
---|
| 17 | except: |
---|
| 18 | def set_trace(): |
---|
| 19 | pass |
---|
| 20 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[1845] | 21 | try: |
---|
| 22 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
| 23 | except: |
---|
| 24 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
[1510] | 25 | aq_courses = context.courses_catalog.evalAdvancedQuery |
---|
| 26 | |
---|
[1571] | 27 | import logging |
---|
| 28 | logger = logging.getLogger('Skins.refresh_level') |
---|
| 29 | |
---|
[1590] | 30 | from urllib import urlencode |
---|
| 31 | |
---|
[1510] | 32 | current = DateTime.DateTime() |
---|
| 33 | request = context.REQUEST |
---|
[1822] | 34 | #session = request.SESSION |
---|
[1510] | 35 | response = request.RESPONSE |
---|
| 36 | redirect = response.redirect |
---|
[1571] | 37 | logger = logging.getLogger('Skins.refresh_level') |
---|
[1510] | 38 | mtool = context.portal_membership |
---|
| 39 | member = mtool.getAuthenticatedMember() |
---|
| 40 | member_id = str(member) |
---|
| 41 | wt = context.waeup_tool |
---|
| 42 | student = context.students_catalog(id=context.getStudentId())[0] |
---|
| 43 | cert_id = student.course |
---|
| 44 | current_level = student.level |
---|
| 45 | level = context |
---|
[1657] | 46 | #results = context.results_import(matric_no = student.matric_no) |
---|
[1873] | 47 | # results = False #skip carry overs |
---|
| 48 | # if results: |
---|
| 49 | # #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
| 50 | # l = [] |
---|
| 51 | # carry_overs = results |
---|
| 52 | # for co in carry_overs: |
---|
| 53 | # carry_over = False |
---|
| 54 | # query = Eq('code',co.CosCode) |
---|
| 55 | # c_res = aq_courses(query) |
---|
| 56 | # if not c_res: |
---|
| 57 | # logger.info('%s, course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
| 58 | # continue |
---|
| 59 | # course_cat_entry = c_res[0] |
---|
| 60 | # if not course_cat_entry.passmark: |
---|
| 61 | # carry_over = co.GRADE in ('D','E','F') |
---|
| 62 | # else: |
---|
| 63 | # try: |
---|
| 64 | # score = int(co.Score) |
---|
| 65 | # except: |
---|
| 66 | # logger.info('%s, course %s has invalid score %s' % (student.id, |
---|
| 67 | # co.CosCode, |
---|
| 68 | # co.Score)) |
---|
| 69 | # continue |
---|
| 70 | # if int(c_res[0].passmark) <= score: |
---|
| 71 | # continue |
---|
| 72 | # carry_over = True |
---|
| 73 | # if not carry_over: |
---|
| 74 | # continue |
---|
| 75 | # d = context.getCourseInfo(co.CosCode) |
---|
| 76 | # d['grade'] = co.GRADE |
---|
| 77 | # d['carry_level'] = co.CarryLevel |
---|
| 78 | # course_id = "%s_co" % co.CosCode |
---|
| 79 | # if not context.hasObject(course_id): |
---|
| 80 | # cr_id = level.invokeFactory('StudentCourseResult',course_id) |
---|
| 81 | # course_result = getattr(level,cr_id) |
---|
| 82 | # context.portal_workflow.doActionFor(course_result,'open') |
---|
| 83 | # course_result.getContent().edit(mapping=d) |
---|
[1510] | 84 | res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
| 85 | l = [] |
---|
| 86 | if res: |
---|
| 87 | cert = res[0] |
---|
| 88 | path = cert.getPath() |
---|
[1657] | 89 | query = Eq("path","%s/%s" % (path,student.level)) &\ |
---|
| 90 | Eq('portal_type','CertificateCourse') |
---|
[1510] | 91 | courses = aq_portal(query) |
---|
[2040] | 92 | course_ids = [c.getId for c in courses if c.getId not in level.objectIds()] |
---|
| 93 | for c_id in course_ids: |
---|
[1657] | 94 | #set_trace() |
---|
[2040] | 95 | d = context.getCourseInfo(c_id) |
---|
| 96 | cr_id = level.invokeFactory('StudentCourseResult',c_id) |
---|
| 97 | course_result = getattr(level,cr_id) |
---|
| 98 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 99 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
| 100 | course_result.getContent().edit(mapping=d) |
---|
| 101 | context.waeup_tool.doCommit() |
---|
[1822] | 102 | #session.set('in_progress','finished') |
---|
[1571] | 103 | logger.info('%s updated course list' % member) |
---|
[1590] | 104 | |
---|
[1591] | 105 | args = {} |
---|
[1590] | 106 | psm = "Course list updated!" |
---|
| 107 | args['portal_status_message'] = psm |
---|
[1606] | 108 | if action_after_validate: |
---|
| 109 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
| 110 | else: |
---|
| 111 | url = context.absolute_url() + '?' + urlencode(args) |
---|
[1590] | 112 | return REQUEST.RESPONSE.redirect(url) |
---|