source: WAeUP_SRP/trunk/skins/waeup_student/getStudyLevelInfo.py @ 1795

Last change on this file since 1795 was 1783, checked in by Henrik Bettermann, 18 years ago
  • assertViewable removed and page templates adjusted, so that no traceback occurs.
  • 'Previous Session' action added
  • waeup_content_master.pt removed
  • and more
  • Property svn:keywords set to Id
File size: 3.5 KB
RevLine 
[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"""
12return Info about the Studylevel
13"""
[1783]14
15wf = context.portal_workflow
16mtool = context.portal_membership
17if mtool.isAnonymousUser():
18    return None
19
[1494]20try:
21    from Products.zdb import set_trace
22except:
23    def set_trace():
24        pass
[1783]25       
26       
[1380]27from Products.AdvancedQuery import Eq, Between, Le,In
[1494]28aq_portal = context.portal_catalog.evalAdvancedQuery
[1380]29request = context.REQUEST
30session = request.SESSION
31response = request.RESPONSE
32
[723]33def 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]50def 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]59student_id = context.getStudentId()
60
[723]61info = {}
[1515]62info['is_so'] = is_so = context.isSectionOfficer()
63info['is_student'] = is_student = context.isStudent()
64info['is_ca'] = is_ca = context.isCourseAdviser()
[1380]65info['student'] = student = context.students_catalog(id=student_id)[0]
[1513]66info['review_state'] = review_state = context.getStudentReviewState()
[1515]67info['view_only'] =  review_state != "school_fee_paid"
[1586]68info['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]71info['choosen_ids'] = request.get('ids',[])
[1513]72info['status_info'] = ""
73if 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"
78elif 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]83info['doc'] = context.getContent()
[1380]84##study_course = context.aq_parent.getContent()
85##cert_id = study_course.study_course
86cert_id = student.course
[723]87info['cert_id'] = cert_id
[1380]88normal = []
89carry_overs = []
[1482]90credits_total = 0
[1380]91for 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]110info['credits_total'] = credits_total
[1641]111carry_overs.sort(cmp_semester_id)
[1380]112info['carry_overs'] = carry_overs
[1641]113normal.sort(cmp_semester_id)
[1380]114info['normal'] = normal
[1575]115
116students_object = context.portal_url.getPortalObject().campus.students
117student = getattr(students_object, student_id)
118info['app'] = student.application
119info['app_doc'] = student.application.getContent()
120
[723]121return info
Note: See TracBrowser for help on using the repository browser.