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