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