[2448] | 1 | ##parameters=
|
---|
| 2 | # $Id: create_level.py 5496 2010-08-25 16:10:37Z 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
|
---|
[2539] | 20 | aq_results = context.course_results.evalAdvancedQuery
|
---|
[2448] | 21 |
|
---|
| 22 | current = DateTime.DateTime()
|
---|
| 23 | request = context.REQUEST
|
---|
| 24 | response = request.RESPONSE
|
---|
| 25 | redirect = response.redirect
|
---|
| 26 | logger = logging.getLogger('Skins.create_level')
|
---|
[2977] | 27 | info = context.waeup_tool.getAccessInfo(context)
|
---|
| 28 | student_id = info['student_id']
|
---|
| 29 | if student_id is None:
|
---|
| 30 | return None
|
---|
[2539] | 31 |
|
---|
[2766] | 32 | student = context.students_catalog.getRecordByKey(student_id)
|
---|
[2448] | 33 | cert_id = student.course
|
---|
| 34 | current_level = student.level
|
---|
| 35 | current_session = student.session
|
---|
| 36 | in_progress = request.get('in_progress','not started')
|
---|
[2539] | 37 | if aq_results(Eq('student_id',student_id) & Eq('level_id',current_level)):
|
---|
| 38 | logger.info('%s tried to create already existing level %s' % (student.id,current_level))
|
---|
[2611] | 39 | return
|
---|
[2448] | 40 |
|
---|
| 41 | if context.hasObject(current_level):
|
---|
[2766] | 42 | return response.redirect("%s/%s" % (context.absolute_url(),current_level))
|
---|
[2448] | 43 | else:
|
---|
| 44 | context.invokeFactory('StudentStudyLevel',"%s" % current_level)
|
---|
| 45 | level = getattr(context,"%s" % current_level)
|
---|
| 46 | context.portal_workflow.doActionFor(level,'open')
|
---|
| 47 | level.getContent().edit(mapping={'session': current_session})
|
---|
| 48 | level_id = level.getId()
|
---|
| 49 | session_id = context.getLevelSession(level.getContent(),student_id,level_id)
|
---|
[2471] | 50 | results = []
|
---|
[2472] | 51 | records = []
|
---|
[2448] | 52 | if student.matric_no:
|
---|
| 53 | results = context.results_import(matric_no = student.matric_no)
|
---|
[2454] | 54 | l = []
|
---|
[2664] | 55 |
|
---|
[2988] | 56 | res = context.portal_catalog(portal_type="Certificate", id = cert_id)
|
---|
| 57 | if res:
|
---|
| 58 | cert = res[0]
|
---|
| 59 | path = cert.getPath()
|
---|
[3074] | 60 | if int(current_level) > 0:
|
---|
| 61 | academics_level = 100 * (int(current_level)/100)
|
---|
| 62 | else:
|
---|
[3650] | 63 | academics_level = '000'
|
---|
[2988] | 64 | query = Eq("path","%s/%s" % (path,academics_level)) &\
|
---|
| 65 | Eq('portal_type','CertificateCourse')
|
---|
| 66 | courses = aq_portal(query)
|
---|
| 67 | for c in courses:
|
---|
| 68 | course_id = "%s" % c.getId
|
---|
| 69 | if course_id in l:
|
---|
| 70 | # don't add twice
|
---|
| 71 | continue
|
---|
| 72 | l += course_id,
|
---|
| 73 | d = context.getCourseInfo(c.getId)
|
---|
| 74 | d['carry_over'] = False
|
---|
| 75 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
|
---|
| 76 | d['course_id'] = course_id
|
---|
| 77 | d['student_id'] = student_id = context.getStudentId()
|
---|
| 78 | d['level_id'] = level_id
|
---|
| 79 | d['session_id'] = session_id
|
---|
| 80 | records.append(d)
|
---|
[2752] | 81 | # fetch carry_over courses from results_import
|
---|
[2454] | 82 | if student.session in ('6', '06') and results:
|
---|
[2448] | 83 | carry_overs = results
|
---|
| 84 | for co in carry_overs:
|
---|
| 85 | course_id = co.CosCode
|
---|
[2988] | 86 | if course_id in l:
|
---|
| 87 | # don't add twice
|
---|
[2448] | 88 | continue
|
---|
[2988] | 89 | # if level.hasObject(course_id): #already created
|
---|
| 90 | # continue
|
---|
[2448] | 91 | carry_over = False
|
---|
| 92 | query = Eq('code',co.CosCode)
|
---|
| 93 | c_res = aq_courses(query)
|
---|
| 94 | if not c_res:
|
---|
| 95 | #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode))
|
---|
| 96 | continue
|
---|
| 97 | course_cat_entry = c_res[0]
|
---|
| 98 | passmark = getattr(course_cat_entry,'passmark',None)
|
---|
[2611] | 99 | if not passmark or not co.Score:
|
---|
[2448] | 100 | carry_over = co.GRADE in ('D','E','F')
|
---|
| 101 | else:
|
---|
| 102 | try:
|
---|
| 103 | score = int(co.Score)
|
---|
| 104 | except:
|
---|
| 105 | # logger.info('%s, course %s has invalid score %s"' % (student.id,
|
---|
| 106 | # course_id,
|
---|
| 107 | # co.Score))
|
---|
| 108 | continue
|
---|
| 109 | if int(c_res[0].passmark) <= score:
|
---|
| 110 | continue
|
---|
| 111 | carry_over = True
|
---|
| 112 | if not carry_over:
|
---|
| 113 | continue
|
---|
| 114 | l += course_id,
|
---|
| 115 | d = context.getCourseInfo(co.CosCode)
|
---|
| 116 | d['course_id'] = course_id
|
---|
| 117 | d['carry_over'] = carry_over
|
---|
| 118 | d['code'] = course_id
|
---|
| 119 | d['student_id'] = student_id
|
---|
| 120 | d['level_id'] = level_id
|
---|
| 121 | d['session_id'] = session_id
|
---|
| 122 | records.append(d)
|
---|
[2752] | 123 | # fetch carry_over courses from the course_results catalog
|
---|
[2988] | 124 | else:
|
---|
[2793] | 125 | res = aq_results(Eq('student_id',student_id),
|
---|
[2766] | 126 | sortSpecs=('level_id',))
|
---|
| 127 | for result in res:
|
---|
| 128 | course_id = result.code
|
---|
[2988] | 129 | if course_id in l:
|
---|
[2766] | 130 | continue
|
---|
| 131 | query = Eq('code',course_id)
|
---|
| 132 | c_res = aq_courses(query)
|
---|
| 133 | if not c_res:
|
---|
| 134 | #logger.info('%s", course %s not found in courses_catalog' % (student.id,result.CosCode))
|
---|
| 135 | continue
|
---|
| 136 | course_cat_entry = c_res[0]
|
---|
[3650] | 137 | #passmark = getattr(course_cat_entry,'passmark',None)
|
---|
[2766] | 138 | try:
|
---|
| 139 | score = int(result.score)
|
---|
| 140 | except:
|
---|
[3650] | 141 | #logger.info('%s, course_result %s has invalid score"' % (student.id,
|
---|
[2766] | 142 | # course_id,
|
---|
[3650] | 143 | # result.score))
|
---|
[2766] | 144 | continue
|
---|
[3650] | 145 | try:
|
---|
| 146 | passmark = int(c_res[0].passmark)
|
---|
| 147 | except:
|
---|
| 148 | logger.info('%s, course %s has invalid passmark %s"' % (student.id,
|
---|
| 149 | course_id,
|
---|
| 150 | c_res[0].passmark))
|
---|
| 151 | continue
|
---|
[2766] | 152 | if int(c_res[0].passmark) <= score:
|
---|
| 153 | continue
|
---|
| 154 | l += course_id,
|
---|
| 155 | d = context.getCourseInfo(course_id)
|
---|
| 156 | d['course_id'] = course_id
|
---|
| 157 | d['carry_over'] = True
|
---|
| 158 | d['code'] = course_id
|
---|
| 159 | d['student_id'] = student_id
|
---|
| 160 | d['level_id'] = level_id
|
---|
| 161 | d['session_id'] = session_id
|
---|
| 162 | records.append(d)
|
---|
[2448] | 163 |
|
---|
| 164 | if records:
|
---|
[3362] | 165 | existing_uids = context.course_results.addMultipleRecords(records)
|
---|
| 166 | if existing_uids:
|
---|
| 167 | logger.info('%s level %s %s existing keys' % (student.id,
|
---|
| 168 | current_level,
|
---|
| 169 | ",".join(existing_uids)))
|
---|
[3650] | 170 |
|
---|
[5496] | 171 | logger.info('%s created level %s' % (student.id,current_level))
|
---|
[2448] | 172 |
|
---|
[3650] | 173 | return response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|