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