[3690] | 1 | ## Script (Python) "getStudyLevelInfo"
|
---|
| 2 | ##bind container=container
|
---|
| 3 | ##bind context=context
|
---|
| 4 | ##bind namespace=
|
---|
| 5 | ##bind script=script
|
---|
| 6 | ##bind subpath=traverse_subpath
|
---|
| 7 | ##parameters=student=None
|
---|
| 8 | ##title=
|
---|
| 9 | ##
|
---|
| 10 | # $Id: getStudyLevelInfo.py 2760 2007-11-26 07:39:15Z henrik $
|
---|
| 11 | """
|
---|
| 12 | return Info about the Studylevel
|
---|
| 13 | try:
|
---|
| 14 | from Products.zdb import set_trace
|
---|
| 15 | except:
|
---|
| 16 | def set_trace():
|
---|
| 17 | pass
|
---|
| 18 | """
|
---|
| 19 |
|
---|
[4098] | 20 | import DateTime
|
---|
| 21 |
|
---|
[3690] | 22 | info = context.waeup_tool.getAccessInfo(context)
|
---|
| 23 | student_id = info['student_id']
|
---|
| 24 | if student_id is None:
|
---|
| 25 | return None
|
---|
| 26 |
|
---|
| 27 | mtool = context.portal_membership
|
---|
[4098] | 28 | pprops = context.portal_properties
|
---|
[3690] | 29 | member = mtool.getAuthenticatedMember()
|
---|
| 30 | member_id = str(member)
|
---|
| 31 |
|
---|
| 32 | course_results = context.course_results
|
---|
| 33 | request = context.REQUEST
|
---|
| 34 | response = request.RESPONSE
|
---|
| 35 | import logging
|
---|
| 36 | logger = logging.getLogger('Skins.getStudyLevelInfo')
|
---|
| 37 |
|
---|
| 38 | level_id = context.getId()
|
---|
| 39 | level_doc = info['doc'] = context.getContent()
|
---|
| 40 |
|
---|
| 41 | info['is_so'] = is_so = info['is_sectionofficer']
|
---|
| 42 | #info['is_student'] = is_student = context.isStudent()
|
---|
| 43 | info['is_ca'] = is_ca = context.isCourseAdviser()
|
---|
| 44 | #info['student'] = student = context.students_catalog(id=student_id)[0]
|
---|
| 45 | info['student'] = student = context.students_catalog.getRecordByKey(student_id)
|
---|
| 46 | info['review_state'] = review_state = student.review_state
|
---|
| 47 | is_current_level = level_id == student.level
|
---|
| 48 | school_fee_paid = review_state == 'school_fee_paid'
|
---|
| 49 | info['is_current_level'] = is_current_level
|
---|
| 50 | info['has_verdict'] = has_verdict = level_doc.verdict
|
---|
| 51 |
|
---|
| 52 | info['submission_allowed']= school_fee_paid and is_current_level and not has_verdict
|
---|
| 53 | info['validation_allowed']= review_state == 'courses_registered' and is_current_level
|
---|
| 54 | info['rejection_allowed']= review_state in ('courses_registered', 'courses_validated',) and is_current_level
|
---|
| 55 | info['validated'] = review_state == 'courses_validated' and is_current_level
|
---|
| 56 |
|
---|
| 57 | info['show_check_boxes'] = (is_ca and school_fee_paid and is_current_level and not has_verdict) or\
|
---|
| 58 | (info['is_student'] and school_fee_paid and is_current_level and not has_verdict) or\
|
---|
| 59 | (is_so and is_current_level and not has_verdict)
|
---|
| 60 |
|
---|
| 61 | info['verdict'] = context.portal_vocabularies.verdicts.get(level_doc.verdict).upper()
|
---|
| 62 | info['session'] = context.portal_vocabularies.sessions.get(level_doc.session)
|
---|
| 63 | info['level_str'] = context.portal_vocabularies.student_levels.get(level_id)
|
---|
| 64 |
|
---|
| 65 | info['choosen_ids'] = request.get('ids',[])
|
---|
| 66 |
|
---|
| 67 | #info['status_info'] = ""
|
---|
| 68 | #if is_student:
|
---|
| 69 | # if review_state == 'courses_registered':
|
---|
| 70 | # info['status_info'] = "Request for course validation pending"
|
---|
| 71 | # elif review_state == 'courses_validated':
|
---|
| 72 | # info['status_info'] = "Courses validated"
|
---|
| 73 | #elif is_ca:
|
---|
| 74 | # if review_state == 'courses_registered':
|
---|
| 75 | # info['status_info'] = "Please validate these courses"
|
---|
| 76 | # elif review_state == 'courses_validated':
|
---|
| 77 | # info['status_info'] = "Courses validated"
|
---|
| 78 |
|
---|
| 79 | cert_id = student.course
|
---|
| 80 | info['cert_id'] = cert_id
|
---|
| 81 | total_credits,gpa,carry_overs,normal1,normal2,normal3 = course_results.getCourses(student_id,level_id)
|
---|
| 82 | info['total_credits'] = total_credits
|
---|
| 83 |
|
---|
| 84 | #start customization
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | max_credits = 58
|
---|
| 89 | info['without_score'] = False
|
---|
| 90 | info['without_cascore'] = False
|
---|
| 91 |
|
---|
| 92 | items = []
|
---|
| 93 | subobjects = context.objectValues()
|
---|
| 94 | for subobject in subobjects:
|
---|
| 95 | row = {}
|
---|
| 96 | row['id'] = subobject.getId()
|
---|
| 97 | row['title'] = '%s' % context.portal_vocabularies.terms.get(subobject.getId())
|
---|
| 98 | items.append(row)
|
---|
| 99 | info['items'] = items
|
---|
| 100 |
|
---|
[3811] | 101 | complete1 = 0
|
---|
[3902] | 102 | score_calc_average_1 = 0
|
---|
[3811] | 103 | for r in normal1:
|
---|
[3902] | 104 | if r['grade'] and r['atl']:
|
---|
| 105 | complete1 += 1
|
---|
| 106 | score_calc_average_1 += r['score_calc']
|
---|
[3811] | 107 | if len(normal1) == complete1:
|
---|
| 108 | complete1 = True
|
---|
| 109 | else:
|
---|
| 110 | complete1 = False
|
---|
[3902] | 111 | if len(normal1):
|
---|
| 112 | score_calc_average_1 /= len(normal1)
|
---|
[3811] | 113 | info['complete1'] = complete1
|
---|
[4035] | 114 | info['score_calc_average_1'] = '%.2f' % score_calc_average_1
|
---|
[3690] | 115 |
|
---|
[3811] | 116 | complete2 = 0
|
---|
[3902] | 117 | score_calc_average_2 = 0
|
---|
[4035] | 118 | for r in normal2:
|
---|
[3902] | 119 | if r['grade'] and r['atl']:
|
---|
| 120 | score_calc_average_2 += r['score_calc']
|
---|
| 121 | complete2 += 1
|
---|
[3811] | 122 | if len(normal2) == complete2:
|
---|
| 123 | complete2 = True
|
---|
| 124 | else:
|
---|
| 125 | complete2 = False
|
---|
[3902] | 126 | if len(normal2):
|
---|
| 127 | score_calc_average_2 /= len(normal2)
|
---|
[3811] | 128 | info['complete2'] = complete2
|
---|
[4035] | 129 | info['score_calc_average_2'] = '%.2f' % score_calc_average_2
|
---|
[3811] | 130 |
|
---|
| 131 | complete3 = 0
|
---|
[3902] | 132 | score_calc_average_3 = 0
|
---|
[4035] | 133 | for r in normal3:
|
---|
[3902] | 134 | if r['grade'] and r['atl']:
|
---|
| 135 | complete3 += 1
|
---|
| 136 | score_calc_average_3 += r['score_calc']
|
---|
[3811] | 137 | if len(normal3) == complete3:
|
---|
| 138 | complete3 = True
|
---|
| 139 | else:
|
---|
| 140 | complete3 = False
|
---|
[3902] | 141 | if len(normal3):
|
---|
| 142 | score_calc_average_3 /= len(normal3)
|
---|
[3811] | 143 | info['complete3'] = complete3
|
---|
[4035] | 144 | info['score_calc_average_3'] = '%.2f' % score_calc_average_3
|
---|
[3811] | 145 |
|
---|
[4036] | 146 | session_id = level_doc.session
|
---|
[4303] | 147 | yga1,yga2,yga3,counter1,counter2,counter3,yg1,yg2,yg3 = course_results.getYearGroupAverage(session_id,level_id)
|
---|
[4036] | 148 | info['yga1'] = yga1
|
---|
| 149 | info['yga2'] = yga2
|
---|
| 150 | info['yga3'] = yga3
|
---|
| 151 | info['counter1'] = counter1
|
---|
| 152 | info['counter2'] = counter2
|
---|
| 153 | info['counter3'] = counter3
|
---|
[3811] | 154 |
|
---|
[4303] | 155 |
|
---|
| 156 | #yg1.sort(reverse=True)
|
---|
| 157 | #if not len(yg1):
|
---|
| 158 | # pos1 = 'no result'
|
---|
| 159 | #for pos1 in range(len(yg1)):
|
---|
| 160 | # if yg1[pos1] <= float(score_calc_average_1):
|
---|
| 161 | # break
|
---|
| 162 | #info['pos1'] = '%d of %d' % (pos1+1,len(yg1))
|
---|
| 163 |
|
---|
[3690] | 164 | #end customization
|
---|
| 165 |
|
---|
| 166 | info['max_credits'] = max_credits
|
---|
| 167 | info['credits_exceeded'] = total_credits > max_credits
|
---|
| 168 | current_session = student.session
|
---|
| 169 |
|
---|
| 170 | info['gpa'] = gpa
|
---|
| 171 | if gpa and total_credits:
|
---|
| 172 | info['gpa'] = "%4.2f" % (float(gpa)/int(total_credits))
|
---|
| 173 |
|
---|
| 174 | info['carry_overs'] = carry_overs
|
---|
[3819] | 175 | normal1.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
|
---|
| 176 | normal2.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
|
---|
| 177 | normal3.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
|
---|
| 178 |
|
---|
[3690] | 179 | info['normal1'] = normal1
|
---|
| 180 | info['normal2'] = normal2
|
---|
| 181 | info['normal3'] = normal3
|
---|
| 182 |
|
---|
| 183 | info['data_missing'] = not info['normal1'] and not info['normal2'] and not info['normal3']
|
---|
| 184 | info['spillover'] = student.level > student.end_level
|
---|
| 185 |
|
---|
| 186 | students_object = context.portal_url.getPortalObject().campus.students
|
---|
| 187 | student = getattr(students_object, student_id)
|
---|
| 188 | info['app'] = student.application
|
---|
| 189 | info['app_doc'] = student.application.getContent()
|
---|
| 190 |
|
---|
[4098] | 191 | if pprops.session == info['session']:
|
---|
| 192 | info['date1'] = DateTime.DateTime(pprops.date1).strftime('%d/%m/%Y')
|
---|
| 193 | info['date2'] = DateTime.DateTime(pprops.date2).strftime('%d/%m/%Y')
|
---|
| 194 | info['date3'] = DateTime.DateTime(pprops.date3).strftime('%d/%m/%Y')
|
---|
| 195 | else:
|
---|
| 196 | info['date1'] = 'n/a'
|
---|
| 197 | info['date2'] = 'n/a'
|
---|
| 198 | info['date3'] = 'n/a'
|
---|
| 199 |
|
---|
[4395] | 200 | info['over_pos_term1'] = getattr(level_doc, 'over_pos_term1','n/a')
|
---|
| 201 | info['no_stud_term1'] = getattr(level_doc, 'no_stud_term1','n/a')
|
---|
[4098] | 202 |
|
---|
[3690] | 203 | return info |
---|