[2448] | 1 | ##parameters=
|
---|
| 2 | # $Id: create_level.py 2489 2007-10-31 11:15:56Z henrik $
|
---|
| 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
|
---|
| 14 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
| 15 | try:
|
---|
| 16 | aq_portal = context.portal_catalog.evalAdvancedQuery
|
---|
| 17 | except:
|
---|
| 18 | aq_portal = context.portal_catalog_real.evalAdvancedQuery
|
---|
| 19 | aq_courses = context.courses_catalog.evalAdvancedQuery
|
---|
| 20 |
|
---|
| 21 | current = DateTime.DateTime()
|
---|
| 22 | request = context.REQUEST
|
---|
| 23 | #session = request.SESSION
|
---|
| 24 | response = request.RESPONSE
|
---|
| 25 | redirect = response.redirect
|
---|
| 26 | logger = logging.getLogger('Skins.create_level')
|
---|
| 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
|
---|
| 34 | current_level = student.level
|
---|
| 35 | current_session = student.session
|
---|
| 36 | in_progress = request.get('in_progress','not started')
|
---|
| 37 | #level_created = request.get('level_created','xxx')
|
---|
| 38 | create_level = request.get('create_level',None)
|
---|
| 39 |
|
---|
| 40 | ##if context.hasObject(current_level) and create_level:
|
---|
| 41 | ## if getattr(context,current_level).objectIds():
|
---|
| 42 | ## logger.info('%s tried to add already existing level %s' % (student.id,current_level))
|
---|
| 43 | ## return
|
---|
| 44 | logger.info('%s started to create level %s' % (student.id,current_level))
|
---|
| 45 |
|
---|
| 46 | ##if in_progress in ('not started','started'):
|
---|
| 47 | ## session.set('in_progress','started')
|
---|
| 48 | ## view = context.in_progress_view(refresh=20,page='create_level?in_progress=started')
|
---|
| 49 | ## response.setHeader('Content-type','text/html; charset=ISO-8859-15')
|
---|
| 50 | ## response.setHeader('Content-length','%d' % (len(view)))
|
---|
| 51 | ## response.setStatus('OK')
|
---|
| 52 | ## response.write(view)
|
---|
| 53 | ## response.write('')
|
---|
| 54 | ## if in_progress == 'started':
|
---|
| 55 | ## return
|
---|
| 56 |
|
---|
| 57 | if context.hasObject(current_level):
|
---|
| 58 | level = getattr(context,"%s" % current_level)
|
---|
| 59 | else:
|
---|
| 60 | context.invokeFactory('StudentStudyLevel',"%s" % current_level)
|
---|
| 61 | level = getattr(context,"%s" % current_level)
|
---|
| 62 | context.portal_workflow.doActionFor(level,'open')
|
---|
| 63 | #study_session = context.getSessionString()
|
---|
| 64 | level.getContent().edit(mapping={'session': current_session})
|
---|
| 65 | context.portal_workflow.doActionFor(level,'close_for_edit')
|
---|
| 66 | #context.waeup_tool.doCommit()
|
---|
| 67 | level_id = level.getId()
|
---|
| 68 | student_id = context.getStudentId()
|
---|
| 69 | session_id = context.getLevelSession(level.getContent(),student_id,level_id)
|
---|
[2471] | 70 | results = []
|
---|
[2472] | 71 | records = []
|
---|
[2448] | 72 | if student.matric_no:
|
---|
| 73 | results = context.results_import(matric_no = student.matric_no)
|
---|
[2454] | 74 | l = []
|
---|
| 75 | if student.session in ('6', '06') and results:
|
---|
[2448] | 76 | carry_overs = results
|
---|
| 77 | for co in carry_overs:
|
---|
| 78 | course_id = co.CosCode
|
---|
| 79 | if level.hasObject(course_id): #already created
|
---|
| 80 | continue
|
---|
| 81 | carry_over = False
|
---|
| 82 | query = Eq('code',co.CosCode)
|
---|
| 83 | c_res = aq_courses(query)
|
---|
| 84 | if not c_res:
|
---|
| 85 | #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode))
|
---|
| 86 | continue
|
---|
| 87 | course_cat_entry = c_res[0]
|
---|
| 88 | passmark = getattr(course_cat_entry,'passmark',None)
|
---|
| 89 | if not passmark:
|
---|
| 90 | carry_over = co.GRADE in ('D','E','F')
|
---|
| 91 | else:
|
---|
| 92 | try:
|
---|
| 93 | score = int(co.Score)
|
---|
| 94 | except:
|
---|
| 95 | # logger.info('%s, course %s has invalid score %s"' % (student.id,
|
---|
| 96 | # course_id,
|
---|
| 97 | # co.Score))
|
---|
| 98 | continue
|
---|
| 99 | if int(c_res[0].passmark) <= score:
|
---|
| 100 | continue
|
---|
| 101 | carry_over = True
|
---|
| 102 | if not carry_over:
|
---|
| 103 | continue
|
---|
| 104 | if course_id in l:
|
---|
| 105 | # don't add twice
|
---|
| 106 | continue
|
---|
| 107 | l += course_id,
|
---|
| 108 | d = context.getCourseInfo(co.CosCode)
|
---|
| 109 | d['course_id'] = course_id
|
---|
[2489] | 110 | #d['grade'] = co.GRADE
|
---|
[2448] | 111 | d['carry_over'] = carry_over
|
---|
| 112 | # course_id = level.invokeFactory('StudentCourseResult',"%s_co" % course_id)
|
---|
| 113 | # course_result = getattr(level,course_id)
|
---|
| 114 | # context.portal_workflow.doActionFor(course_result,'open')
|
---|
| 115 | # course_result.getContent().edit(mapping=d)
|
---|
| 116 | # context.waeup_tool.doCommit()
|
---|
| 117 | d['code'] = course_id
|
---|
| 118 | d['student_id'] = student_id
|
---|
| 119 | d['level_id'] = level_id
|
---|
| 120 | d['session_id'] = session_id
|
---|
| 121 | records.append(d)
|
---|
| 122 |
|
---|
| 123 | #level['create_course_results'](cert_id,current_level)
|
---|
| 124 | res = context.portal_catalog(portal_type="Certificate", id = cert_id)
|
---|
| 125 | if res:
|
---|
| 126 | cert = res[0]
|
---|
| 127 | path = cert.getPath()
|
---|
| 128 | query = Eq("path","%s/%s" % (path,current_level)) &\
|
---|
| 129 | Eq('portal_type','CertificateCourse')
|
---|
| 130 | courses = aq_portal(query)
|
---|
| 131 | for c in courses:
|
---|
| 132 | course_id = "%s" % c.getId
|
---|
| 133 | if course_id in l:
|
---|
| 134 | # don't add twice
|
---|
| 135 | continue
|
---|
| 136 | l += course_id,
|
---|
| 137 | d = context.getCourseInfo(c.getId)
|
---|
| 138 | # course_id = level.invokeFactory('StudentCourseResult',c.getId)
|
---|
| 139 | # course_result = getattr(level,course_id)
|
---|
| 140 | # context.portal_workflow.doActionFor(course_result,'open')
|
---|
| 141 | # d['core_or_elective'] = True
|
---|
| 142 | # course_result.getContent().edit(mapping=d)
|
---|
| 143 | # context.waeup_tool.doCommit()
|
---|
| 144 | d['carry_over'] = False
|
---|
| 145 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
|
---|
| 146 | d['course_id'] = course_id
|
---|
| 147 | d['student_id'] = student_id = context.getStudentId()
|
---|
| 148 | d['level_id'] = level_id
|
---|
| 149 | d['session_id'] = session_id
|
---|
| 150 | #context.course_results.addRecord(**d)
|
---|
| 151 | records.append(d)
|
---|
| 152 | if records:
|
---|
| 153 | context.course_results.addMultipleRecords(records)
|
---|
| 154 | logger.info('%s finished to create level %s' % (student.id,current_level))
|
---|
| 155 |
|
---|
[2454] | 156 | #if current_session == '05':
|
---|
| 157 | # next_session = '06'
|
---|
| 158 | # next_level = "%s" % (int(current_level) + 100)
|
---|
| 159 | # study_course = getattr(student,'study_course')
|
---|
| 160 | # context.portal_workflow.doActionFor(study_course,'open')
|
---|
| 161 | # study_course_doc = study_course.getContent()
|
---|
| 162 | # study_course_doc.edit(mapping= {'current_level': next_level,
|
---|
| 163 | # 'current_session': next_session,})
|
---|
| 164 | # context.portal_workflow.doActionFor(study_course,'close_for_edit')
|
---|
[2448] | 165 |
|
---|
[2489] | 166 | return response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|