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

Last change on this file since 1851 was 1845, checked in by joachim, 18 years ago

modifications to use QueueCatalog?

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1##parameters=
2# $Id: create_level.py 1845 2007-06-02 11:01:49Z 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
15try:
16    aq_portal = context.portal_catalog.evalAdvancedQuery
17except:
18    aq_portal = context.portal_catalog_real.evalAdvancedQuery
19aq_courses = context.courses_catalog.evalAdvancedQuery
20
21current = DateTime.DateTime()
22request = context.REQUEST
23#session = request.SESSION
24response = request.RESPONSE
25redirect = response.redirect
26logger = logging.getLogger('Skins.create_level')
27mtool = context.portal_membership
28member = mtool.getAuthenticatedMember()
29member_id = str(member)
30lt = context.portal_layouts
31wt = context.waeup_tool
32student = context.students_catalog(id=context.getStudentId())[0]
33cert_id = student.course
34current_level = student.level
35in_progress =  request.get('in_progress','not started')
36level_created =  request.get('level_created','xxx')
37create_level =  request.get('create_level',None)
38
39if context.hasObject(current_level) and create_level :
40    logger.info('%s tried to add already existing level %s' % (student.id,current_level))
41    return
42logger.info('%s started to create level %s' % (student.id,current_level))
43
44##if in_progress in ('not started','started'):
45##    session.set('in_progress','started')
46##    view = context.in_progress_view(refresh=20,page='create_level?in_progress=started')
47##    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
48##    response.setHeader('Content-length','%d' % (len(view)))
49##    response.setStatus('OK')
50##    response.write(view)
51##    response.write('')
52##    if in_progress == 'started':
53##        return
54
55if level_created == current_level:
56    level = getattr(context,"%s" % current_level)
57else:
58    context.invokeFactory('StudentStudyLevel',"%s" % current_level)
59    level = getattr(context,"%s" % current_level)
60    context.portal_workflow.doActionFor(level,'open')
61    study_session = context.getSessionString()
62    level.getContent().edit(mapping={'session': study_session})
63    context.portal_workflow.doActionFor(level,'close_for_edit')
64results = []
65if student.matric_no:
66    results = context.results_import(matric_no = student.matric_no)
67if results:
68    #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
69    l = []
70    carry_overs = results
71   
72    # carry_overs for probation students: yes or not, that is the question
73    #if student.verdict == "C": # on probation
74    #    carry_overs = []
75
76    for co in carry_overs:
77        carry_over = False
78        query = Eq('code',co.CosCode)
79        c_res = aq_courses(query)
80        if not c_res:
81            #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode))
82            continue
83        course_cat_entry = c_res[0]
84        passmark = getattr(course_cat_entry,'passmark',None)
85        if not passmark:
86            carry_over = co.GRADE in ('D','E','F')
87        else:
88            try:
89                score = int(co.Score)
90            except:
91                # logger.info('%s, course %s has invalid score %s"' % (student.id,
92                #                                                     co.CosCode,
93                #                                                     co.Score))
94                continue
95            if int(c_res[0].passmark) <= score:
96                continue
97            carry_over = True
98        if not carry_over:
99            continue
100        d = context.getCourseInfo(co.CosCode)
101        d['grade'] = co.GRADE
102        d['carry_level'] = co.CarryLevel
103        cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode)
104        course_result = getattr(level,cr_id)
105        context.portal_workflow.doActionFor(course_result,'open')
106        course_result.getContent().edit(mapping=d)
107        #context.waeup_tool.doCommit()
108#level['create_course_results'](cert_id,current_level)
109res = context.portal_catalog(portal_type="Certificate", id = cert_id)
110l = []
111if res:
112    cert = res[0]
113    path = cert.getPath()
114    #set_trace()
115    query = Eq("path","%s/%s" % (path,current_level)) &\
116            Eq('portal_type','CertificateCourse')
117    courses = aq_portal(query)
118    for c in courses:
119        d = context.getCourseInfo(c.getId)
120        cr_id = level.invokeFactory('StudentCourseResult',c.getId)
121        course_result = getattr(level,cr_id)
122        context.portal_workflow.doActionFor(course_result,'open')
123        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
124        course_result.getContent().edit(mapping=d)
125        #context.waeup_tool.doCommit()
126logger.info('%s finished to create level %s' % (student.id,current_level))
127return response.redirect("%s/%s" % (context.absolute_url(),current_level))
128
Note: See TracBrowser for help on using the repository browser.