source: WAeUP_SRP/trunk/skins/waeup_student/create_level.py @ 1743

Last change on this file since 1743 was 1701, checked in by joachim, 18 years ago

allow new students to register courses

  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1##parameters=
2# $Id: create_level.py 1701 2007-04-24 08:40:52Z 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('Skins.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 =  request.get('in_progress','not started')
33level_created =  request.get('level_created','xxx')
34create_level =  request.get('create_level',None)
35
36if context.hasObject(current_level) and create_level :
37    logger.info('%s tried to add already existing level %s' % (student.id,current_level))
38    return
39
40##if in_progress in ('not started','started'):
41##    session.set('in_progress','started')
42##    view = context.in_progress_view(refresh=20,page='create_level?in_progress=started')
43##    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
44##    response.setHeader('Content-length','%d' % (len(view)))
45##    response.setStatus('OK')
46##    response.write(view)
47##    response.write('')
48##    if in_progress == 'started':
49##        return
50
51if level_created == current_level:
52    level = getattr(context,"%s" % current_level)
53else:
54    context.invokeFactory('StudentStudyLevel',"%s" % current_level)
55    logger.info('%s created level %s' % (student.id,current_level))
56    level = getattr(context,"%s" % current_level)
57    context.portal_workflow.doActionFor(level,'open')
58    study_session = context.getSessionString()
59    level.getContent().edit(mapping={'session': study_session})
60    context.portal_workflow.doActionFor(level,'close_for_edit')
61results = []
62if student.matric_no:
63    results = context.results_import(matric_no = student.matric_no)
64if results:
65    #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
66    l = []
67    carry_overs = results
68    for co in carry_overs:
69        carry_over = False
70        query = Eq('code',co.CosCode)
71        c_res = aq_courses(query)
72        if not c_res:
73            logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode))
74            continue
75        course_cat_entry = c_res[0]
76        passmark = getattr(course_cat_entry,'passmark',None)
77        if not passmark:
78            carry_over = co.GRADE in ('D','E','F')
79        else:
80            try:
81                score = int(co.Score)
82            except:
83                logger.info('%s, course %s has invalid score %s"' % (student.id,
84                                                                    co.CosCode,
85                                                                    co.Score))
86                continue
87            if int(c_res[0].passmark) <= score:
88                continue
89            carry_over = True
90        if not carry_over:
91            continue
92        d = context.getCourseInfo(co.CosCode)
93        d['grade'] = co.GRADE
94        d['carry_level'] = co.CarryLevel
95        cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode)
96        course_result = getattr(level,cr_id)
97        context.portal_workflow.doActionFor(course_result,'open')
98        course_result.getContent().edit(mapping=d)
99level['create_course_results'](cert_id,current_level)
100##res = context.portal_catalog(portal_type="Certificate", id = cert_id)
101##l = []
102##if res:
103##    cert = res[0]
104##    path = cert.getPath()
105##    #set_trace()
106##    query = Eq("path","%s/%s" % (path,current_level)) &\
107##            Eq('portal_type','CertificateCourse')
108##    courses = aq_portal(query)
109##    for c in courses:
110##        d = context.getCourseInfo(c.getId)
111##        cr_id = level.invokeFactory('StudentCourseResult',c.getId)
112##        course_result = getattr(level,cr_id)
113##        context.portal_workflow.doActionFor(course_result,'open')
114##        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
115##        course_result.getContent().edit(mapping=d)
116
117return response.redirect("%s/%s" % (context.absolute_url(),current_level))
118
Note: See TracBrowser for help on using the repository browser.