[2448] | 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
|
---|
| 7 | ##parameters=REQUEST=None, student=None, action_after_reject=None, action_after_validate=None
|
---|
| 8 | # $Id: refresh_level.py 2451 2007-10-27 14:26:41Z 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
|
---|
| 21 | try:
|
---|
| 22 | aq_portal = context.portal_catalog.evalAdvancedQuery
|
---|
| 23 | except:
|
---|
| 24 | aq_portal = context.portal_catalog_real.evalAdvancedQuery
|
---|
| 25 | aq_courses = context.courses_catalog.evalAdvancedQuery
|
---|
| 26 |
|
---|
| 27 | import logging
|
---|
| 28 | logger = logging.getLogger('Skins.refresh_level')
|
---|
| 29 |
|
---|
| 30 | from urllib import urlencode
|
---|
| 31 |
|
---|
| 32 | current = DateTime.DateTime()
|
---|
| 33 | request = context.REQUEST
|
---|
| 34 | #session = request.SESSION
|
---|
| 35 | response = request.RESPONSE
|
---|
| 36 | redirect = response.redirect
|
---|
| 37 | logger = logging.getLogger('Skins.refresh_level')
|
---|
| 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
|
---|
| 46 | #results = context.results_import(matric_no = student.matric_no)
|
---|
| 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)
|
---|
| 84 | res = context.portal_catalog(portal_type="Certificate", id = cert_id)
|
---|
| 85 | l = []
|
---|
| 86 | if res:
|
---|
| 87 | cert = res[0]
|
---|
| 88 | path = cert.getPath()
|
---|
| 89 | query = Eq("path","%s/%s" % (path,student.level)) &\
|
---|
| 90 | Eq('portal_type','CertificateCourse')
|
---|
| 91 | courses = aq_portal(query)
|
---|
| 92 | course_ids = [c.getId for c in courses if c.getId not in level.objectIds()]
|
---|
| 93 | for course_id in course_ids:
|
---|
| 94 | #set_trace()
|
---|
| 95 | d = context.getCourseInfo(course_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 | # course_result.getContent().edit(mapping=d)
|
---|
| 100 | # context.waeup_tool.doCommit()
|
---|
| 101 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
|
---|
| 102 | #d['core_or_elective'] = True
|
---|
| 103 | d['course_id'] = course_id
|
---|
| 104 | d['student_id'] = student_id = context.getStudentId()
|
---|
| 105 | d['level_id'] = level_id = context.getId()
|
---|
| 106 | d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
|
---|
| 107 | context.course_results.addRecord(**d)
|
---|
| 108 | #session.set('in_progress','finished')
|
---|
| 109 | logger.info('%s updated course list' % member)
|
---|
| 110 |
|
---|
| 111 | args = {}
|
---|
| 112 | psm = "Course list updated!"
|
---|
| 113 | args['portal_status_message'] = psm
|
---|
| 114 | if action_after_validate:
|
---|
| 115 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
|
---|
| 116 | else:
|
---|
| 117 | url = context.absolute_url() + '?' + urlencode(args)
|
---|
[2451] | 118 | return REQUEST.RESPONSE.redirect(url)
|
---|