source: WAeUP_SRP/branches/regebro-noskins/skins/waeup_student/create_level.py

Last change on this file was 1513, checked in by joachim, 18 years ago

register courses

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1##parameters=
2# $Id: create_level.py 1513 2007-03-02 22:59:45Z joachim $
3"""
4process the Application Form
5return html renderer + psm
6"""
7request = context.REQUEST
8import DateTime,logging
9try:
10    from Products.zdb import set_trace
11except:
12    def set_trace():
13        pass
14from Products.AdvancedQuery import Eq, Between, Le,In
15aq_portal = context.portal_catalog.evalAdvancedQuery
16aq_courses = context.courses_catalog.evalAdvancedQuery
17
18current = DateTime.DateTime()
19request = context.REQUEST
20session = request.SESSION
21response = request.RESPONSE
22redirect = response.redirect
23logger = logging.getLogger('Student.create_level')
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26member_id = str(member)
27lt = context.portal_layouts
28wt = context.waeup_tool
29student = context.students_catalog(id=context.getStudentId())[0]
30cert_id = student.course
31current_level = student.level
32in_progress =  session.get('in_progress','finished')
33if in_progress == 'finished':
34    session.set('in_progress','started')
35    view = context.in_progress_view(refresh=3,page='%s/study_level_view' % current_level)
36    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
37    response.setHeader('Content-length','%d' % (len(view)))
38    response.setStatus('OK')
39    response.write(view)
40    response.write('')
41elif in_progress == 'started':
42    return
43context.invokeFactory('StudentStudyLevel',"%s" % current_level)
44level = getattr(context,"%s" % current_level)
45context.portal_workflow.doActionFor(level,'open')
46study_session = context.getSessionString()
47level.getContent().edit(mapping={'session': study_session})
48context.portal_workflow.doActionFor(level,'close_for_edit')
49results = context.results_import(matric_no = student.matric_no)
50if results:
51    #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
52    l = []
53    carry_overs = results
54    for co in carry_overs:
55        carry_over = False
56        query = Eq('code',co.CosCode)
57        c_res = aq_courses(query)
58        if not c_res:
59            logger.info('"%s","%s course not found in courses catalog"' % (student.id,co.CosCode))
60            continue
61        course_cat_entry = c_res[0]
62        passmark = getattr(course_cat_entry,'passmark',None)
63        if not passmark:
64            carry_over = co.GRADE in ('D','E','F')
65        else:
66            try:
67                score = int(co.Score)
68            except:
69                logger.info('"%s"," course %s invalid score %s"' % (student.id,
70                                                                    co.CosCode,
71                                                                    co.Score))
72                continue
73            if int(c_res[0].passmark) <= score: 
74                continue
75            carry_over = True
76        if not carry_over:
77            continue
78        d = context.getCourseInfo(co.CosCode)
79        d['grade'] = co.GRADE
80        d['carry_level'] = co.CarryLevel
81        cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode)
82        course_result = getattr(level,cr_id)
83        context.portal_workflow.doActionFor(course_result,'open')
84        course_result.getContent().edit(mapping=d)
85res = context.portal_catalog(portal_type="Certificate", id = cert_id)
86l = []
87if res:
88    cert = res[0]
89    path = cert.getPath()
90    query = Eq("path",path) &\
91            Eq('portal_type','CertificateCourse') &\
92            Eq('SearchableText', "%s" % student.level)
93    courses = aq_portal(query)
94    for c in courses:
95        d = context.getCourseInfo(c.getId)
96        cr_id = level.invokeFactory('StudentCourseResult',c.getId)
97        course_result = getattr(level,cr_id)
98        context.portal_workflow.doActionFor(course_result,'open')
99        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
100        course_result.getContent().edit(mapping=d)
101session.set('in_progress','finished')
102return
103return response.redirect("%s" % level.absolute_url())
Note: See TracBrowser for help on using the repository browser.