[727] | 1 | # Script (Python) "cpsdocument_edit" |
---|
[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 805 2006-11-09 09:38:29Z joachim $ |
---|
[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['is_manager'] = context.isManager() |
---|
| 47 | info['is_student'] = context.isStudent() |
---|
| 48 | info['action'] = "%s" % context.absolute_url() |
---|
| 49 | info['choosen_ids'] = request.get('ids',[]) |
---|
| 50 | info['doc'] = context.getContent() |
---|
[724] | 51 | study_course = context.aq_parent.getContent() |
---|
[723] | 52 | cert_id = study_course.study_course |
---|
| 53 | brain = context.portal_catalog(meta_type="Student",id = student_id)[-1] |
---|
| 54 | cp = brain.getPath() |
---|
| 55 | info['container_path'] = cp |
---|
| 56 | info['cert_id'] = cert_id |
---|
| 57 | |
---|
[724] | 58 | res = context.portal_catalog(meta_type="StudentCourseResult", |
---|
[723] | 59 | container_path="%s/study_course/%s" % (cp,level_id)) |
---|
| 60 | first = [] |
---|
| 61 | second = [] |
---|
| 62 | sum = 0 |
---|
| 63 | course_count = 0 |
---|
| 64 | for r in res: |
---|
| 65 | row = {} |
---|
| 66 | ro = r.getObject() |
---|
| 67 | rd = ro.getContent() |
---|
| 68 | row['id'] = ro.getId() |
---|
[727] | 69 | row['credits'] = rd.credits |
---|
[723] | 70 | if row['credits'] and rd.grade: |
---|
[727] | 71 | credits = int(rd.credits) |
---|
[724] | 72 | sum += credits * ['F','E','D','C','B','A'].index(rd.grade) |
---|
[723] | 73 | course_count += credits |
---|
| 74 | row['sum'] = sum |
---|
| 75 | row['count'] = course_count |
---|
[727] | 76 | row['title'] = rd.title |
---|
[723] | 77 | #row['core'] = rd.core_or_elective |
---|
| 78 | row['semester'] = rd.semester |
---|
| 79 | row['score'] = rd.score |
---|
| 80 | row['grade'] = rd.grade |
---|
| 81 | row['weight'] = rd.weight |
---|
| 82 | row['url'] = ro.absolute_url() |
---|
| 83 | row['review_state'] = wf.getInfoFor(ro,'review_state','None') |
---|
| 84 | row['is_editable'] = mtool.checkPermission('Modify portal content', ro) |
---|
| 85 | if rd.semester == 1: |
---|
| 86 | first.append(row) |
---|
| 87 | else: |
---|
| 88 | second.append(row) |
---|
| 89 | first.sort() |
---|
| 90 | second.sort() |
---|
| 91 | gpaf = 0.0 |
---|
| 92 | if course_count: |
---|
| 93 | gpaf = (float(sum)/course_count) |
---|
[724] | 94 | gpa = "%4.2f" % gpaf |
---|
[725] | 95 | info['doc'].edit(mapping={'gpa': gpaf}) |
---|
[723] | 96 | info['first'] = first |
---|
| 97 | info['second'] = second |
---|
| 98 | return info |
---|