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