[845] | 1 | # Script (Python) "getStudyLevelInfo" |
---|
[723] | 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 | ## |
---|
[805] | 10 | # $Id: getStudyLevelInfo.py 913 2006-11-21 10:49:45Z henrik $ |
---|
[723] | 11 | """ |
---|
| 12 | return Info about the Studylevel |
---|
| 13 | """ |
---|
| 14 | def calculateGPA(): |
---|
| 15 | """calculate the gpa""" |
---|
| 16 | sum = 0 |
---|
| 17 | course_count = 0 |
---|
| 18 | for sc in context.objectValues(): |
---|
| 19 | result = sc.getContent() |
---|
| 20 | if not result.grade: |
---|
| 21 | continue |
---|
| 22 | res = context.portal_catalog({'meta_type': 'Course', |
---|
| 23 | 'id': sc.aq_parent.id}) |
---|
| 24 | if len(res) < 1: |
---|
| 25 | continue |
---|
| 26 | course = res[0].getObject().getContent() |
---|
| 27 | if course_count: |
---|
| 28 | return sum/course_count |
---|
| 29 | return 0.0 |
---|
| 30 | |
---|
| 31 | request = context.REQUEST |
---|
| 32 | |
---|
| 33 | wf = context.portal_workflow |
---|
| 34 | mtool = context.portal_membership |
---|
| 35 | path_info = request.get('PATH_INFO').split('/') |
---|
| 36 | try: |
---|
| 37 | i = int(path_info[-1]) |
---|
| 38 | p = 0 |
---|
| 39 | except: |
---|
| 40 | p = 1 |
---|
| 41 | info = {} |
---|
| 42 | pt = request.get('PATH_TRANSLATED').split('/') |
---|
| 43 | |
---|
| 44 | student_id = pt[-(3+p)] |
---|
| 45 | level_id = pt[-(1+p)] |
---|
| 46 | info['action'] = "%s" % context.absolute_url() |
---|
| 47 | info['choosen_ids'] = request.get('ids',[]) |
---|
| 48 | info['doc'] = context.getContent() |
---|
[724] | 49 | study_course = context.aq_parent.getContent() |
---|
[723] | 50 | cert_id = study_course.study_course |
---|
| 51 | brain = context.portal_catalog(meta_type="Student",id = student_id)[-1] |
---|
| 52 | cp = brain.getPath() |
---|
| 53 | info['container_path'] = cp |
---|
| 54 | info['cert_id'] = cert_id |
---|
| 55 | |
---|
[724] | 56 | res = context.portal_catalog(meta_type="StudentCourseResult", |
---|
[723] | 57 | container_path="%s/study_course/%s" % (cp,level_id)) |
---|
| 58 | first = [] |
---|
| 59 | second = [] |
---|
| 60 | sum = 0 |
---|
| 61 | course_count = 0 |
---|
| 62 | for r in res: |
---|
| 63 | row = {} |
---|
| 64 | ro = r.getObject() |
---|
| 65 | rd = ro.getContent() |
---|
| 66 | row['id'] = ro.getId() |
---|
[727] | 67 | row['credits'] = rd.credits |
---|
[723] | 68 | if row['credits'] and rd.grade: |
---|
[727] | 69 | credits = int(rd.credits) |
---|
[724] | 70 | sum += credits * ['F','E','D','C','B','A'].index(rd.grade) |
---|
[723] | 71 | course_count += credits |
---|
| 72 | row['sum'] = sum |
---|
| 73 | row['count'] = course_count |
---|
[727] | 74 | row['title'] = rd.title |
---|
[723] | 75 | #row['core'] = rd.core_or_elective |
---|
| 76 | row['semester'] = rd.semester |
---|
| 77 | row['score'] = rd.score |
---|
| 78 | row['grade'] = rd.grade |
---|
| 79 | row['weight'] = rd.weight |
---|
| 80 | row['url'] = ro.absolute_url() |
---|
| 81 | row['review_state'] = wf.getInfoFor(ro,'review_state','None') |
---|
| 82 | row['is_editable'] = mtool.checkPermission('Modify portal content', ro) |
---|
| 83 | if rd.semester == 1: |
---|
| 84 | first.append(row) |
---|
| 85 | else: |
---|
| 86 | second.append(row) |
---|
| 87 | first.sort() |
---|
| 88 | second.sort() |
---|
| 89 | gpaf = 0.0 |
---|
| 90 | if course_count: |
---|
| 91 | gpaf = (float(sum)/course_count) |
---|
[724] | 92 | gpa = "%4.2f" % gpaf |
---|
[725] | 93 | info['doc'].edit(mapping={'gpa': gpaf}) |
---|
[723] | 94 | info['first'] = first |
---|
| 95 | info['second'] = second |
---|
| 96 | return info |
---|