[1492] | 1 | ##parameters= |
---|
| 2 | # $Id: create_level.py 1856 2007-06-05 13:06:23Z 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 |
---|
[1845] | 15 | try: |
---|
| 16 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
| 17 | except: |
---|
| 18 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
[1498] | 19 | aq_courses = context.courses_catalog.evalAdvancedQuery |
---|
[1492] | 20 | |
---|
| 21 | current = DateTime.DateTime() |
---|
| 22 | request = context.REQUEST |
---|
[1822] | 23 | #session = request.SESSION |
---|
[1492] | 24 | response = request.RESPONSE |
---|
| 25 | redirect = response.redirect |
---|
[1571] | 26 | logger = logging.getLogger('Skins.create_level') |
---|
[1492] | 27 | mtool = context.portal_membership |
---|
| 28 | member = mtool.getAuthenticatedMember() |
---|
| 29 | member_id = str(member) |
---|
| 30 | lt = context.portal_layouts |
---|
| 31 | wt = context.waeup_tool |
---|
| 32 | student = context.students_catalog(id=context.getStudentId())[0] |
---|
| 33 | cert_id = student.course |
---|
[1494] | 34 | current_level = student.level |
---|
[1576] | 35 | in_progress = request.get('in_progress','not started') |
---|
[1652] | 36 | level_created = request.get('level_created','xxx') |
---|
| 37 | create_level = request.get('create_level',None) |
---|
[1576] | 38 | |
---|
[1856] | 39 | ##if context.hasObject(current_level) and create_level: |
---|
| 40 | ## if getattr(context,current_level).objectIds(): |
---|
| 41 | ## logger.info('%s tried to add already existing level %s' % (student.id,current_level)) |
---|
| 42 | ## return |
---|
[1845] | 43 | logger.info('%s started to create level %s' % (student.id,current_level)) |
---|
[1576] | 44 | |
---|
[1639] | 45 | ##if in_progress in ('not started','started'): |
---|
| 46 | ## session.set('in_progress','started') |
---|
| 47 | ## view = context.in_progress_view(refresh=20,page='create_level?in_progress=started') |
---|
| 48 | ## response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 49 | ## response.setHeader('Content-length','%d' % (len(view))) |
---|
| 50 | ## response.setStatus('OK') |
---|
| 51 | ## response.write(view) |
---|
| 52 | ## response.write('') |
---|
| 53 | ## if in_progress == 'started': |
---|
| 54 | ## return |
---|
[1659] | 55 | |
---|
[1856] | 56 | if context.hasObject(current_level): |
---|
[1652] | 57 | level = getattr(context,"%s" % current_level) |
---|
| 58 | else: |
---|
| 59 | context.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
| 60 | level = getattr(context,"%s" % current_level) |
---|
| 61 | context.portal_workflow.doActionFor(level,'open') |
---|
| 62 | study_session = context.getSessionString() |
---|
| 63 | level.getContent().edit(mapping={'session': study_session}) |
---|
| 64 | context.portal_workflow.doActionFor(level,'close_for_edit') |
---|
[1856] | 65 | context.waeup_tool.doCommit() |
---|
[1701] | 66 | results = [] |
---|
| 67 | if student.matric_no: |
---|
| 68 | results = context.results_import(matric_no = student.matric_no) |
---|
[1495] | 69 | if results: |
---|
[1498] | 70 | #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
[1495] | 71 | l = [] |
---|
[1498] | 72 | carry_overs = results |
---|
[1770] | 73 | |
---|
| 74 | # carry_overs for probation students: yes or not, that is the question |
---|
| 75 | #if student.verdict == "C": # on probation |
---|
| 76 | # carry_overs = [] |
---|
| 77 | |
---|
[1495] | 78 | for co in carry_overs: |
---|
[1856] | 79 | cr_id = "%s_co" % co.CosCode |
---|
| 80 | if level.hasObject(cr_id): #already created |
---|
| 81 | continue |
---|
[1498] | 82 | carry_over = False |
---|
| 83 | query = Eq('code',co.CosCode) |
---|
| 84 | c_res = aq_courses(query) |
---|
| 85 | if not c_res: |
---|
[1845] | 86 | #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
[1498] | 87 | continue |
---|
| 88 | course_cat_entry = c_res[0] |
---|
[1513] | 89 | passmark = getattr(course_cat_entry,'passmark',None) |
---|
| 90 | if not passmark: |
---|
[1498] | 91 | carry_over = co.GRADE in ('D','E','F') |
---|
| 92 | else: |
---|
| 93 | try: |
---|
| 94 | score = int(co.Score) |
---|
| 95 | except: |
---|
[1845] | 96 | # logger.info('%s, course %s has invalid score %s"' % (student.id, |
---|
| 97 | # co.CosCode, |
---|
| 98 | # co.Score)) |
---|
[1498] | 99 | continue |
---|
[1571] | 100 | if int(c_res[0].passmark) <= score: |
---|
[1498] | 101 | continue |
---|
| 102 | carry_over = True |
---|
| 103 | if not carry_over: |
---|
| 104 | continue |
---|
[1495] | 105 | d = context.getCourseInfo(co.CosCode) |
---|
| 106 | d['grade'] = co.GRADE |
---|
| 107 | d['carry_level'] = co.CarryLevel |
---|
| 108 | cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode) |
---|
| 109 | course_result = getattr(level,cr_id) |
---|
| 110 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 111 | course_result.getContent().edit(mapping=d) |
---|
[1856] | 112 | context.waeup_tool.doCommit() |
---|
[1811] | 113 | #level['create_course_results'](cert_id,current_level) |
---|
| 114 | res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
| 115 | l = [] |
---|
| 116 | if res: |
---|
| 117 | cert = res[0] |
---|
| 118 | path = cert.getPath() |
---|
| 119 | #set_trace() |
---|
| 120 | query = Eq("path","%s/%s" % (path,current_level)) &\ |
---|
| 121 | Eq('portal_type','CertificateCourse') |
---|
| 122 | courses = aq_portal(query) |
---|
| 123 | for c in courses: |
---|
[1856] | 124 | cr_id = "%s" % c.getId |
---|
| 125 | if level.hasObject(cr_id): #already created |
---|
| 126 | continue |
---|
[1811] | 127 | d = context.getCourseInfo(c.getId) |
---|
| 128 | cr_id = level.invokeFactory('StudentCourseResult',c.getId) |
---|
| 129 | course_result = getattr(level,cr_id) |
---|
| 130 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 131 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
| 132 | course_result.getContent().edit(mapping=d) |
---|
[1856] | 133 | context.waeup_tool.doCommit() |
---|
[1823] | 134 | logger.info('%s finished to create level %s' % (student.id,current_level)) |
---|
[1635] | 135 | return response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|
| 136 | |
---|