[1492] | 1 | ##parameters= |
---|
| 2 | # $Id: create_level.py 1653 2007-03-28 02:35:25Z uli $ |
---|
| 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 |
---|
[1593] | 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 |
---|
[1593] | 32 | in_progress = request.get('in_progress','not started') |
---|
[1653] | 33 | level_created = request.get('level_created','xxx') |
---|
| 34 | create_level = request.get('create_level',None) |
---|
[1593] | 35 | |
---|
[1653] | 36 | if context.hasObject(current_level) and create_level : |
---|
| 37 | logger.info('%s", level %s already exists' % (student.id,current_level)) |
---|
[1593] | 38 | return |
---|
| 39 | |
---|
[1653] | 40 | ##if in_progress in ('not started','started'): |
---|
| 41 | ## session.set('in_progress','started') |
---|
| 42 | ## view = context.in_progress_view(refresh=20,page='create_level?in_progress=started') |
---|
| 43 | ## response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 44 | ## response.setHeader('Content-length','%d' % (len(view))) |
---|
| 45 | ## response.setStatus('OK') |
---|
| 46 | ## response.write(view) |
---|
| 47 | ## response.write('') |
---|
| 48 | ## if in_progress == 'started': |
---|
| 49 | ## return |
---|
[1593] | 50 | |
---|
[1653] | 51 | if level_created == current_level: |
---|
| 52 | level = getattr(context,"%s" % current_level) |
---|
| 53 | else: |
---|
| 54 | context.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
| 55 | level = getattr(context,"%s" % current_level) |
---|
| 56 | context.portal_workflow.doActionFor(level,'open') |
---|
| 57 | study_session = context.getSessionString() |
---|
| 58 | level.getContent().edit(mapping={'session': study_session}) |
---|
| 59 | context.portal_workflow.doActionFor(level,'close_for_edit') |
---|
| 60 | response.redirect("%s?level_created=%s" % (context.absolute_url(),current_level)) |
---|
[1492] | 61 | results = context.results_import(matric_no = student.matric_no) |
---|
[1495] | 62 | if results: |
---|
[1498] | 63 | #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
[1495] | 64 | l = [] |
---|
[1498] | 65 | carry_overs = results |
---|
[1495] | 66 | for co in carry_overs: |
---|
[1498] | 67 | carry_over = False |
---|
| 68 | query = Eq('code',co.CosCode) |
---|
| 69 | c_res = aq_courses(query) |
---|
| 70 | if not c_res: |
---|
[1593] | 71 | logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
[1498] | 72 | continue |
---|
| 73 | course_cat_entry = c_res[0] |
---|
[1513] | 74 | passmark = getattr(course_cat_entry,'passmark',None) |
---|
| 75 | if not passmark: |
---|
[1498] | 76 | carry_over = co.GRADE in ('D','E','F') |
---|
| 77 | else: |
---|
| 78 | try: |
---|
| 79 | score = int(co.Score) |
---|
| 80 | except: |
---|
[1593] | 81 | logger.info('%s, course %s has invalid score %s"' % (student.id, |
---|
[1498] | 82 | co.CosCode, |
---|
| 83 | co.Score)) |
---|
| 84 | continue |
---|
[1593] | 85 | if int(c_res[0].passmark) <= score: |
---|
[1498] | 86 | continue |
---|
| 87 | carry_over = True |
---|
| 88 | if not carry_over: |
---|
| 89 | continue |
---|
[1495] | 90 | d = context.getCourseInfo(co.CosCode) |
---|
| 91 | d['grade'] = co.GRADE |
---|
| 92 | d['carry_level'] = co.CarryLevel |
---|
| 93 | cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode) |
---|
| 94 | course_result = getattr(level,cr_id) |
---|
| 95 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 96 | course_result.getContent().edit(mapping=d) |
---|
[1653] | 97 | level['create_course_results'](cert_id,current_level) |
---|
| 98 | ##res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
| 99 | ##l = [] |
---|
| 100 | ##if res: |
---|
| 101 | ## cert = res[0] |
---|
| 102 | ## path = cert.getPath() |
---|
| 103 | ## #set_trace() |
---|
| 104 | ## query = Eq("path","%s/%s" % (path,current_level)) &\ |
---|
| 105 | ## Eq('portal_type','CertificateCourse') |
---|
| 106 | ## courses = aq_portal(query) |
---|
| 107 | ## for c in courses: |
---|
| 108 | ## d = context.getCourseInfo(c.getId) |
---|
| 109 | ## cr_id = level.invokeFactory('StudentCourseResult',c.getId) |
---|
| 110 | ## course_result = getattr(level,cr_id) |
---|
| 111 | ## context.portal_workflow.doActionFor(course_result,'open') |
---|
| 112 | ## d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
| 113 | ## course_result.getContent().edit(mapping=d) |
---|
| 114 | |
---|
| 115 | return response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|
| 116 | |
---|