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