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

Last change on this file since 1838 was 1823, checked in by joachim, 17 years ago

version in custom

  • Property svn:keywords set to Id
File size: 4.7 KB
RevLine 
[1492]1##parameters=
2# $Id: create_level.py 1823 2007-05-25 14:00:57Z 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
[1494]14from Products.AdvancedQuery import Eq, Between, Le,In
15aq_portal = context.portal_catalog.evalAdvancedQuery
[1498]16aq_courses = context.courses_catalog.evalAdvancedQuery
[1492]17
18current = DateTime.DateTime()
19request = context.REQUEST
[1822]20#session = request.SESSION
[1492]21response = request.RESPONSE
22redirect = response.redirect
[1571]23logger = logging.getLogger('Skins.create_level')
[1492]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
[1494]31current_level = student.level
[1576]32in_progress =  request.get('in_progress','not started')
[1652]33level_created =  request.get('level_created','xxx')
34create_level =  request.get('create_level',None)
[1576]35
[1652]36if context.hasObject(current_level) and create_level :
[1676]37    logger.info('%s tried to add already existing level %s' % (student.id,current_level))
[1576]38    return
39
[1639]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
[1659]50
[1652]51if level_created == current_level:
52    level = getattr(context,"%s" % current_level)
53else:
54    context.invokeFactory('StudentStudyLevel',"%s" % current_level)
[1823]55    logger.info('%s started to create level %s' % (student.id,current_level))
[1652]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')
[1701]61results = []
62if student.matric_no:
63    results = context.results_import(matric_no = student.matric_no)
[1495]64if results:
[1498]65    #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
[1495]66    l = []
[1498]67    carry_overs = results
[1770]68   
69    # carry_overs for probation students: yes or not, that is the question
70    #if student.verdict == "C": # on probation
71    #    carry_overs = []
72
[1495]73    for co in carry_overs:
[1498]74        carry_over = False
75        query = Eq('code',co.CosCode)
76        c_res = aq_courses(query)
77        if not c_res:
[1571]78            logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode))
[1498]79            continue
80        course_cat_entry = c_res[0]
[1513]81        passmark = getattr(course_cat_entry,'passmark',None)
82        if not passmark:
[1498]83            carry_over = co.GRADE in ('D','E','F')
84        else:
85            try:
86                score = int(co.Score)
87            except:
[1571]88                logger.info('%s, course %s has invalid score %s"' % (student.id,
[1498]89                                                                    co.CosCode,
90                                                                    co.Score))
91                continue
[1571]92            if int(c_res[0].passmark) <= score:
[1498]93                continue
94            carry_over = True
95        if not carry_over:
96            continue
[1495]97        d = context.getCourseInfo(co.CosCode)
98        d['grade'] = co.GRADE
99        d['carry_level'] = co.CarryLevel
100        cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode)
101        course_result = getattr(level,cr_id)
102        context.portal_workflow.doActionFor(course_result,'open')
103        course_result.getContent().edit(mapping=d)
[1823]104        #context.waeup_tool.doCommit()
[1811]105#level['create_course_results'](cert_id,current_level)
106res = context.portal_catalog(portal_type="Certificate", id = cert_id)
107l = []
108if res:
109    cert = res[0]
110    path = cert.getPath()
111    #set_trace()
112    query = Eq("path","%s/%s" % (path,current_level)) &\
113            Eq('portal_type','CertificateCourse')
114    courses = aq_portal(query)
115    for c in courses:
116        d = context.getCourseInfo(c.getId)
117        cr_id = level.invokeFactory('StudentCourseResult',c.getId)
118        course_result = getattr(level,cr_id)
119        context.portal_workflow.doActionFor(course_result,'open')
120        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
121        course_result.getContent().edit(mapping=d)
[1823]122        #context.waeup_tool.doCommit()
123logger.info('%s finished to create level %s' % (student.id,current_level))
[1635]124return response.redirect("%s/%s" % (context.absolute_url(),current_level))
125
Note: See TracBrowser for help on using the repository browser.