[2448] | 1 | ##parameters=
|
---|
| 2 | # $Id: create_level.py 2539 2007-11-05 18:07:42Z joachim $
|
---|
| 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')
|
---|
| 27 | mtool = context.portal_membership
|
---|
| 28 | member = mtool.getAuthenticatedMember()
|
---|
| 29 | member_id = str(member)
|
---|
[2539] | 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 |
|
---|
[2448] | 39 | lt = context.portal_layouts
|
---|
| 40 | wt = context.waeup_tool
|
---|
[2539] | 41 | student = context.students_catalog(id=student_id)[0]
|
---|
[2448] | 42 | cert_id = student.course
|
---|
| 43 | current_level = student.level
|
---|
| 44 | current_session = student.session
|
---|
| 45 | in_progress = request.get('in_progress','not started')
|
---|
[2539] | 46 | if aq_results(Eq('student_id',student_id) & Eq('level_id',current_level)):
|
---|
| 47 | logger.info('%s tried to create already existing level %s' % (student.id,current_level))
|
---|
| 48 | return
|
---|
[2448] | 49 |
|
---|
| 50 | logger.info('%s started to create level %s' % (student.id,current_level))
|
---|
| 51 |
|
---|
| 52 | if context.hasObject(current_level):
|
---|
| 53 | level = getattr(context,"%s" % current_level)
|
---|
| 54 | else:
|
---|
| 55 | context.invokeFactory('StudentStudyLevel',"%s" % current_level)
|
---|
| 56 | level = getattr(context,"%s" % current_level)
|
---|
| 57 | context.portal_workflow.doActionFor(level,'open')
|
---|
| 58 | level.getContent().edit(mapping={'session': current_session})
|
---|
| 59 | context.portal_workflow.doActionFor(level,'close_for_edit')
|
---|
| 60 | level_id = level.getId()
|
---|
| 61 | session_id = context.getLevelSession(level.getContent(),student_id,level_id)
|
---|
[2471] | 62 | results = []
|
---|
[2472] | 63 | records = []
|
---|
[2448] | 64 | if student.matric_no:
|
---|
| 65 | results = context.results_import(matric_no = student.matric_no)
|
---|
[2454] | 66 | l = []
|
---|
| 67 | if student.session in ('6', '06') and results:
|
---|
[2448] | 68 | carry_overs = results
|
---|
| 69 | for co in carry_overs:
|
---|
| 70 | course_id = co.CosCode
|
---|
| 71 | if level.hasObject(course_id): #already created
|
---|
| 72 | continue
|
---|
| 73 | carry_over = False
|
---|
| 74 | query = Eq('code',co.CosCode)
|
---|
| 75 | c_res = aq_courses(query)
|
---|
| 76 | if not c_res:
|
---|
| 77 | #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode))
|
---|
| 78 | continue
|
---|
| 79 | course_cat_entry = c_res[0]
|
---|
| 80 | passmark = getattr(course_cat_entry,'passmark',None)
|
---|
| 81 | if not passmark:
|
---|
| 82 | carry_over = co.GRADE in ('D','E','F')
|
---|
| 83 | else:
|
---|
| 84 | try:
|
---|
| 85 | score = int(co.Score)
|
---|
| 86 | except:
|
---|
| 87 | # logger.info('%s, course %s has invalid score %s"' % (student.id,
|
---|
| 88 | # course_id,
|
---|
| 89 | # co.Score))
|
---|
| 90 | continue
|
---|
| 91 | if int(c_res[0].passmark) <= score:
|
---|
| 92 | continue
|
---|
| 93 | carry_over = True
|
---|
| 94 | if not carry_over:
|
---|
| 95 | continue
|
---|
| 96 | if course_id in l:
|
---|
| 97 | # don't add twice
|
---|
| 98 | continue
|
---|
| 99 | l += course_id,
|
---|
| 100 | d = context.getCourseInfo(co.CosCode)
|
---|
| 101 | d['course_id'] = course_id
|
---|
| 102 | d['carry_over'] = carry_over
|
---|
| 103 | d['code'] = course_id
|
---|
| 104 | d['student_id'] = student_id
|
---|
| 105 | d['level_id'] = level_id
|
---|
| 106 | d['session_id'] = session_id
|
---|
| 107 | records.append(d)
|
---|
| 108 |
|
---|
| 109 | res = context.portal_catalog(portal_type="Certificate", id = cert_id)
|
---|
| 110 | if res:
|
---|
| 111 | cert = res[0]
|
---|
| 112 | path = cert.getPath()
|
---|
| 113 | query = Eq("path","%s/%s" % (path,current_level)) &\
|
---|
| 114 | Eq('portal_type','CertificateCourse')
|
---|
| 115 | courses = aq_portal(query)
|
---|
| 116 | for c in courses:
|
---|
| 117 | course_id = "%s" % c.getId
|
---|
| 118 | if course_id in l:
|
---|
| 119 | # don't add twice
|
---|
| 120 | continue
|
---|
| 121 | l += course_id,
|
---|
| 122 | d = context.getCourseInfo(c.getId)
|
---|
| 123 | d['carry_over'] = False
|
---|
| 124 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
|
---|
| 125 | d['course_id'] = course_id
|
---|
| 126 | d['student_id'] = student_id = context.getStudentId()
|
---|
| 127 | d['level_id'] = level_id
|
---|
| 128 | d['session_id'] = session_id
|
---|
| 129 | records.append(d)
|
---|
| 130 | if records:
|
---|
| 131 | context.course_results.addMultipleRecords(records)
|
---|
| 132 | logger.info('%s finished to create level %s' % (student.id,current_level))
|
---|
| 133 |
|
---|
[2539] | 134 | return response.redirect("%s/%s" % (context.absolute_url(),current_level))
|
---|