[1492] | 1 | ##parameters= |
---|
| 2 | # $Id: create_level.py 1639 2007-03-26 14:31:22Z joachim $ |
---|
| 3 | """ |
---|
| 4 | process the Application Form |
---|
| 5 | return html renderer + psm |
---|
| 6 | """ |
---|
| 7 | request = context.REQUEST |
---|
| 8 | import DateTime,logging |
---|
| 9 | try: |
---|
| 10 | from Products.zdb import set_trace |
---|
| 11 | except: |
---|
| 12 | def set_trace(): |
---|
| 13 | pass |
---|
[1494] | 14 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 15 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
[1498] | 16 | aq_courses = context.courses_catalog.evalAdvancedQuery |
---|
[1492] | 17 | |
---|
| 18 | current = DateTime.DateTime() |
---|
| 19 | request = context.REQUEST |
---|
| 20 | session = request.SESSION |
---|
| 21 | response = request.RESPONSE |
---|
| 22 | redirect = response.redirect |
---|
[1571] | 23 | logger = logging.getLogger('Skins.create_level') |
---|
[1492] | 24 | mtool = context.portal_membership |
---|
| 25 | member = mtool.getAuthenticatedMember() |
---|
| 26 | member_id = str(member) |
---|
| 27 | lt = context.portal_layouts |
---|
| 28 | wt = context.waeup_tool |
---|
| 29 | student = context.students_catalog(id=context.getStudentId())[0] |
---|
| 30 | cert_id = student.course |
---|
[1494] | 31 | current_level = student.level |
---|
[1576] | 32 | in_progress = request.get('in_progress','not started') |
---|
| 33 | |
---|
| 34 | if context.hasObject(current_level): |
---|
[1639] | 35 | logger.info('%s", level %s already exists' % (student.id,current_level)) |
---|
[1576] | 36 | response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|
| 37 | return |
---|
| 38 | |
---|
[1639] | 39 | ##if in_progress in ('not started','started'): |
---|
| 40 | ## session.set('in_progress','started') |
---|
| 41 | ## view = context.in_progress_view(refresh=20,page='create_level?in_progress=started') |
---|
| 42 | ## response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 43 | ## response.setHeader('Content-length','%d' % (len(view))) |
---|
| 44 | ## response.setStatus('OK') |
---|
| 45 | ## response.write(view) |
---|
| 46 | ## response.write('') |
---|
| 47 | ## if in_progress == 'started': |
---|
| 48 | ## return |
---|
[1576] | 49 | |
---|
[1552] | 50 | |
---|
[1492] | 51 | context.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
| 52 | level = getattr(context,"%s" % current_level) |
---|
[1495] | 53 | context.portal_workflow.doActionFor(level,'open') |
---|
[1494] | 54 | study_session = context.getSessionString() |
---|
| 55 | level.getContent().edit(mapping={'session': study_session}) |
---|
[1492] | 56 | context.portal_workflow.doActionFor(level,'close_for_edit') |
---|
| 57 | results = context.results_import(matric_no = student.matric_no) |
---|
[1495] | 58 | if results: |
---|
[1498] | 59 | #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
[1495] | 60 | l = [] |
---|
[1498] | 61 | carry_overs = results |
---|
[1495] | 62 | for co in carry_overs: |
---|
[1498] | 63 | carry_over = False |
---|
| 64 | query = Eq('code',co.CosCode) |
---|
| 65 | c_res = aq_courses(query) |
---|
| 66 | if not c_res: |
---|
[1571] | 67 | logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
[1498] | 68 | continue |
---|
| 69 | course_cat_entry = c_res[0] |
---|
[1513] | 70 | passmark = getattr(course_cat_entry,'passmark',None) |
---|
| 71 | if not passmark: |
---|
[1498] | 72 | carry_over = co.GRADE in ('D','E','F') |
---|
| 73 | else: |
---|
| 74 | try: |
---|
| 75 | score = int(co.Score) |
---|
| 76 | except: |
---|
[1571] | 77 | logger.info('%s, course %s has invalid score %s"' % (student.id, |
---|
[1498] | 78 | co.CosCode, |
---|
| 79 | co.Score)) |
---|
| 80 | continue |
---|
[1571] | 81 | if int(c_res[0].passmark) <= score: |
---|
[1498] | 82 | continue |
---|
| 83 | carry_over = True |
---|
| 84 | if not carry_over: |
---|
| 85 | continue |
---|
[1495] | 86 | d = context.getCourseInfo(co.CosCode) |
---|
| 87 | d['grade'] = co.GRADE |
---|
| 88 | d['carry_level'] = co.CarryLevel |
---|
| 89 | cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode) |
---|
| 90 | course_result = getattr(level,cr_id) |
---|
| 91 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 92 | course_result.getContent().edit(mapping=d) |
---|
[1492] | 93 | res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
| 94 | l = [] |
---|
| 95 | if res: |
---|
| 96 | cert = res[0] |
---|
| 97 | path = cert.getPath() |
---|
| 98 | query = Eq("path",path) &\ |
---|
| 99 | Eq('portal_type','CertificateCourse') &\ |
---|
[1635] | 100 | Eq('SearchableText', "%s" % current_level) |
---|
[1494] | 101 | courses = aq_portal(query) |
---|
[1492] | 102 | for c in courses: |
---|
| 103 | d = context.getCourseInfo(c.getId) |
---|
[1494] | 104 | cr_id = level.invokeFactory('StudentCourseResult',c.getId) |
---|
[1495] | 105 | course_result = getattr(level,cr_id) |
---|
| 106 | context.portal_workflow.doActionFor(course_result,'open') |
---|
[1492] | 107 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
[1495] | 108 | course_result.getContent().edit(mapping=d) |
---|
[1635] | 109 | |
---|
| 110 | return response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|
| 111 | |
---|