[2448] | 1 | ## Script (Python) "getStudyLevelInfo"
|
---|
| 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: getStudyLevelInfo.py 2454 2007-10-27 21:53:04Z henrik $
|
---|
| 11 | """
|
---|
| 12 | return Info about the Studylevel
|
---|
| 13 | """
|
---|
| 14 |
|
---|
| 15 | wf = context.portal_workflow
|
---|
| 16 | mtool = context.portal_membership
|
---|
| 17 | if mtool.isAnonymousUser():
|
---|
| 18 | return None
|
---|
| 19 |
|
---|
| 20 | try:
|
---|
| 21 | from Products.zdb import set_trace
|
---|
| 22 | except:
|
---|
| 23 | def set_trace():
|
---|
| 24 | pass
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | # from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
| 28 | # try:
|
---|
| 29 | # aq_portal = context.portal_catalog.evalAdvancedQuery
|
---|
| 30 | # except:
|
---|
| 31 | # aq_portal = context.portal_catalog_real.evalAdvancedQuery
|
---|
| 32 | course_results = context.course_results
|
---|
| 33 | request = context.REQUEST
|
---|
| 34 | response = request.RESPONSE
|
---|
| 35 | import logging
|
---|
| 36 | logger = logging.getLogger('Skins.getStudyLevelInfo')
|
---|
| 37 |
|
---|
| 38 | def calculateGPA():
|
---|
| 39 | """calculate the gpa"""
|
---|
| 40 | sum = 0
|
---|
| 41 | course_count = 0
|
---|
| 42 | for sc in context.objectValues():
|
---|
| 43 | result = sc.getContent()
|
---|
| 44 | if not result.grade:
|
---|
| 45 | continue
|
---|
| 46 | res = context.portal_catalog({'meta_type': 'Course',
|
---|
| 47 | 'id': sc.aq_parent.id})
|
---|
| 48 | if len(res) < 1:
|
---|
| 49 | continue
|
---|
| 50 | course = res[0].getObject().getContent()
|
---|
| 51 | if course_count:
|
---|
| 52 | return sum/course_count
|
---|
| 53 | return 0.0
|
---|
| 54 |
|
---|
| 55 | def cmp_semester_id(a,b):
|
---|
| 56 | s1 = "%(semester)s%(id)s" % a
|
---|
| 57 | s2 = "%(semester)s%(id)s" % b
|
---|
| 58 | if s1 == s2:
|
---|
| 59 | return 0
|
---|
| 60 | if s1 > s2:
|
---|
| 61 | return 1
|
---|
| 62 | return -1
|
---|
| 63 |
|
---|
| 64 | student_id = context.getStudentId()
|
---|
| 65 | level_id = context.getId()
|
---|
| 66 |
|
---|
| 67 | info = {}
|
---|
| 68 | info['is_so'] = is_so = context.isSectionOfficer()
|
---|
| 69 | info['is_student'] = is_student = context.isStudent()
|
---|
| 70 | info['is_ca'] = is_ca = context.isCourseAdviser()
|
---|
| 71 | info['student'] = student = context.students_catalog(id=student_id)[0]
|
---|
| 72 | info['review_state'] = review_state = context.getStudentReviewState()
|
---|
| 73 | info['view_only'] = review_state != "school_fee_paid"
|
---|
| 74 | info['show_check_boxes'] = (is_ca and review_state in ('school_fee_paid',)) or\
|
---|
| 75 | (is_student and context.getStudentReviewState() == "school_fee_paid") or\
|
---|
| 76 | (is_so)
|
---|
| 77 | info['choosen_ids'] = request.get('ids',[])
|
---|
| 78 | info['status_info'] = ""
|
---|
| 79 | if is_student:
|
---|
| 80 | if review_state == 'courses_registered':
|
---|
| 81 | info['status_info'] = "Request for Course Validation pending"
|
---|
| 82 | elif review_state == 'courses_validated':
|
---|
| 83 | info['status_info'] = "Courses validated"
|
---|
| 84 | elif is_ca:
|
---|
| 85 | if review_state == 'courses_registered':
|
---|
| 86 | info['status_info'] = "Please validate these Courses"
|
---|
| 87 | elif review_state == 'courses_validated':
|
---|
| 88 | info['status_info'] = "Courses validated"
|
---|
| 89 | info['doc'] = context.getContent()
|
---|
| 90 | cert_id = student.course
|
---|
| 91 | info['cert_id'] = cert_id
|
---|
| 92 | if context.objectIds():
|
---|
| 93 | course_results.moveResultsHere(context,student_id)
|
---|
| 94 | logger.info("%s moved courseresults and deleted objects in level %s" % (student_id,level_id))
|
---|
| 95 | credits_total,carry_overs,normal = course_results.getCourses(student_id,level_id)
|
---|
| 96 | info['credits_total'] = credits_total
|
---|
| 97 | info['credits_exceeded'] = credits_total > 51
|
---|
| 98 | current_session = student.session
|
---|
[2454] | 99 | info['submission_allowed']= not info['credits_exceeded'] and current_session == context.getSessionId()[0]
|
---|
[2448] | 100 | # carry_overs.sort(cmp_semester_id)
|
---|
| 101 | info['carry_overs'] = carry_overs
|
---|
| 102 | # normal.sort(cmp_semester_id)
|
---|
| 103 | info['normal'] = normal
|
---|
| 104 |
|
---|
| 105 | students_object = context.portal_url.getPortalObject().campus.students
|
---|
| 106 | student = getattr(students_object, student_id)
|
---|
| 107 | info['app'] = student.application
|
---|
| 108 | info['app_doc'] = student.application.getContent()
|
---|
| 109 |
|
---|
[2454] | 110 | return info |
---|