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

Last change on this file since 1484 was 1482, checked in by joachim, 18 years ago

add course registration.
The Link to the study_level is disabled in study_course_view.pt,
but can be invoked manually. On first invocation the courses are created.

  • Property svn:keywords set to Id
File size: 2.1 KB
RevLine 
[845]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 1482 2007-02-23 16:56:46Z joachim $
[723]11"""
12return Info about the Studylevel
13"""
[1380]14from Products.AdvancedQuery import Eq, Between, Le,In
15evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
16request = context.REQUEST
17session = request.SESSION
18response = request.RESPONSE
19
[723]20def calculateGPA():
21    """calculate the gpa"""
22    sum = 0
23    course_count = 0
24    for sc in context.objectValues():
25        result = sc.getContent()
26        if not result.grade:
27            continue
28        res = context.portal_catalog({'meta_type': 'Course',
29                                      'id': sc.aq_parent.id})
30        if len(res) < 1:
31            continue
32        course = res[0].getObject().getContent()
33    if course_count:
34        return sum/course_count
35    return 0.0
36
[1380]37def cmp_semester(a,b):
38    if a['semester'] == b['semester']:
39        return 0
40    if a['semester'] > b['semester']:
41        return 1
42    return -1
[723]43
[1380]44
[723]45wf = context.portal_workflow
46mtool = context.portal_membership
[1380]47student_id = context.getStudentId()
48
[723]49info = {}
[1380]50info['student'] = student = context.students_catalog(id=student_id)[0]
[723]51info['choosen_ids'] = request.get('ids',[])
52info['doc'] = context.getContent()
[1380]53##study_course = context.aq_parent.getContent()
54##cert_id = study_course.study_course
55cert_id = student.course
[723]56info['cert_id'] = cert_id
[1380]57normal = []
58carry_overs = []
[1482]59credits_total = 0
[1380]60for id,obj in context.objectItems():
[1482]61    try:
62        credit = int(obj.getContent().credits)
63    except ValueError:
64        credit = 3
65    credits_total += credit
[1380]66    if id.endswith('_co'):
67        d = context.getCourseInfo(id[:-3])
68        d['grade'] = obj.getContent().grade
69        carry_overs.append(d)
70    else:
71        d = context.getCourseInfo(id)
72        coe = obj.getContent().core_or_elective
73        d['coe'] = 'Core'
74        if not coe:
75            d['coe'] = 'Elective'
76        normal.append(d)
[1482]77info['credits_total'] = credits_total
[1380]78carry_overs.sort(cmp_semester)
79info['carry_overs'] = carry_overs
80normal.sort(cmp_semester)
81info['normal'] = normal
[723]82return info
Note: See TracBrowser for help on using the repository browser.