| [1513] | 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 1653 2007-03-28 02:35:25Z uli $ |
|---|
| [723] | 11 | """ |
|---|
| 12 | return Info about the Studylevel |
|---|
| 13 | """ |
|---|
| [1494] | 14 | try: |
|---|
| 15 | from Products.zdb import set_trace |
|---|
| 16 | except: |
|---|
| 17 | def set_trace(): |
|---|
| 18 | pass |
|---|
| [1380] | 19 | from Products.AdvancedQuery import Eq, Between, Le,In |
|---|
| [1494] | 20 | aq_portal = context.portal_catalog.evalAdvancedQuery |
|---|
| [1380] | 21 | request = context.REQUEST |
|---|
| 22 | session = request.SESSION |
|---|
| 23 | response = request.RESPONSE |
|---|
| 24 | |
|---|
| [723] | 25 | def calculateGPA(): |
|---|
| 26 | """calculate the gpa""" |
|---|
| 27 | sum = 0 |
|---|
| 28 | course_count = 0 |
|---|
| 29 | for sc in context.objectValues(): |
|---|
| 30 | result = sc.getContent() |
|---|
| 31 | if not result.grade: |
|---|
| 32 | continue |
|---|
| 33 | res = context.portal_catalog({'meta_type': 'Course', |
|---|
| 34 | 'id': sc.aq_parent.id}) |
|---|
| 35 | if len(res) < 1: |
|---|
| 36 | continue |
|---|
| 37 | course = res[0].getObject().getContent() |
|---|
| 38 | if course_count: |
|---|
| 39 | return sum/course_count |
|---|
| 40 | return 0.0 |
|---|
| 41 | |
|---|
| [1653] | 42 | def cmp_semester_id(a,b): |
|---|
| 43 | s1 = "%(semester)s%(id)s" % a |
|---|
| 44 | s2 = "%(semester)s%(id)s" % b |
|---|
| 45 | if s1 == s2: |
|---|
| [1380] | 46 | return 0 |
|---|
| [1653] | 47 | if s1 > s2: |
|---|
| [1380] | 48 | return 1 |
|---|
| 49 | return -1 |
|---|
| [723] | 50 | |
|---|
| [1380] | 51 | |
|---|
| [723] | 52 | wf = context.portal_workflow |
|---|
| 53 | mtool = context.portal_membership |
|---|
| [1380] | 54 | student_id = context.getStudentId() |
|---|
| 55 | |
|---|
| [1515] | 56 | |
|---|
| 57 | |
|---|
| [723] | 58 | info = {} |
|---|
| [1515] | 59 | info['is_so'] = is_so = context.isSectionOfficer() |
|---|
| 60 | info['is_student'] = is_student = context.isStudent() |
|---|
| 61 | info['is_ca'] = is_ca = context.isCourseAdviser() |
|---|
| [1380] | 62 | info['student'] = student = context.students_catalog(id=student_id)[0] |
|---|
| [1513] | 63 | info['review_state'] = review_state = context.getStudentReviewState() |
|---|
| [1515] | 64 | info['view_only'] = review_state != "school_fee_paid" |
|---|
| [1593] | 65 | info['show_check_boxes'] = (is_ca and review_state in ('school_fee_paid',)) or\ |
|---|
| [1515] | 66 | (is_student and context.getStudentReviewState() == "school_fee_paid") or\ |
|---|
| 67 | (is_so) |
|---|
| [723] | 68 | info['choosen_ids'] = request.get('ids',[]) |
|---|
| [1513] | 69 | info['status_info'] = "" |
|---|
| 70 | if is_student: |
|---|
| [1515] | 71 | if review_state == 'courses_registered': |
|---|
| [1513] | 72 | info['status_info'] = "Request for Course Validation pending" |
|---|
| [1515] | 73 | elif review_state == 'courses_validated': |
|---|
| [1513] | 74 | info['status_info'] = "Courses validated" |
|---|
| 75 | elif is_ca: |
|---|
| [1515] | 76 | if review_state == 'courses_registered': |
|---|
| [1513] | 77 | info['status_info'] = "Please validate these Courses" |
|---|
| [1515] | 78 | elif review_state == 'courses_validated': |
|---|
| [1513] | 79 | info['status_info'] = "Courses validated" |
|---|
| [723] | 80 | info['doc'] = context.getContent() |
|---|
| [1380] | 81 | ##study_course = context.aq_parent.getContent() |
|---|
| 82 | ##cert_id = study_course.study_course |
|---|
| 83 | cert_id = student.course |
|---|
| [723] | 84 | info['cert_id'] = cert_id |
|---|
| [1380] | 85 | normal = [] |
|---|
| 86 | carry_overs = [] |
|---|
| [1482] | 87 | credits_total = 0 |
|---|
| [1380] | 88 | for id,obj in context.objectItems(): |
|---|
| [1482] | 89 | try: |
|---|
| 90 | credit = int(obj.getContent().credits) |
|---|
| 91 | except ValueError: |
|---|
| 92 | credit = 3 |
|---|
| 93 | credits_total += credit |
|---|
| [1380] | 94 | if id.endswith('_co'): |
|---|
| 95 | d = context.getCourseInfo(id[:-3]) |
|---|
| [1494] | 96 | d['id'] = id |
|---|
| [1380] | 97 | d['grade'] = obj.getContent().grade |
|---|
| 98 | carry_overs.append(d) |
|---|
| 99 | else: |
|---|
| 100 | d = context.getCourseInfo(id) |
|---|
| [1494] | 101 | d['id'] = id |
|---|
| [1380] | 102 | coe = obj.getContent().core_or_elective |
|---|
| 103 | d['coe'] = 'Core' |
|---|
| 104 | if not coe: |
|---|
| 105 | d['coe'] = 'Elective' |
|---|
| 106 | normal.append(d) |
|---|
| [1482] | 107 | info['credits_total'] = credits_total |
|---|
| [1653] | 108 | carry_overs.sort(cmp_semester_id) |
|---|
| [1380] | 109 | info['carry_overs'] = carry_overs |
|---|
| [1653] | 110 | normal.sort(cmp_semester_id) |
|---|
| [1380] | 111 | info['normal'] = normal |
|---|
| [1593] | 112 | |
|---|
| 113 | students_object = context.portal_url.getPortalObject().campus.students |
|---|
| 114 | student = getattr(students_object, student_id) |
|---|
| 115 | info['app'] = student.application |
|---|
| 116 | info['app_doc'] = student.application.getContent() |
|---|
| 117 | |
|---|
| [723] | 118 | return info |
|---|