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

Last change on this file since 2128 was 2033, checked in by joachim, 17 years ago

add course too registered_courses only for current_level

  • Property svn:keywords set to Id
File size: 5.6 KB
RevLine 
[1492]1##parameters=
2# $Id: create_level.py 2033 2007-07-18 13:44:13Z 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
[1845]15try:
16    aq_portal = context.portal_catalog.evalAdvancedQuery
17except:
18    aq_portal = context.portal_catalog_real.evalAdvancedQuery
[1498]19aq_courses = context.courses_catalog.evalAdvancedQuery
[1492]20
21current = DateTime.DateTime()
22request = context.REQUEST
[1822]23#session = request.SESSION
[1492]24response = request.RESPONSE
25redirect = response.redirect
[1571]26logger = logging.getLogger('Skins.create_level')
[1492]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
[1494]34current_level = student.level
[2031]35current_session = student.session
[1576]36in_progress =  request.get('in_progress','not started')
[1986]37#level_created =  request.get('level_created','xxx')
[1652]38create_level =  request.get('create_level',None)
[1576]39
[1856]40##if context.hasObject(current_level) and create_level:
41##    if getattr(context,current_level).objectIds():
42##        logger.info('%s tried to add already existing level %s' % (student.id,current_level))
43##    return
[1845]44logger.info('%s started to create level %s' % (student.id,current_level))
[1576]45
[1639]46##if in_progress in ('not started','started'):
47##    session.set('in_progress','started')
48##    view = context.in_progress_view(refresh=20,page='create_level?in_progress=started')
49##    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
50##    response.setHeader('Content-length','%d' % (len(view)))
51##    response.setStatus('OK')
52##    response.write(view)
53##    response.write('')
54##    if in_progress == 'started':
55##        return
[1659]56
[1856]57if context.hasObject(current_level):
[1652]58    level = getattr(context,"%s" % current_level)
59else:
60    context.invokeFactory('StudentStudyLevel',"%s" % current_level)
61    level = getattr(context,"%s" % current_level)
62    context.portal_workflow.doActionFor(level,'open')
[2031]63    #study_session = context.getSessionString()
64    level.getContent().edit(mapping={'session': current_session})
[1652]65    context.portal_workflow.doActionFor(level,'close_for_edit')
[1856]66    context.waeup_tool.doCommit()
[1701]67results = []
68if student.matric_no:
69    results = context.results_import(matric_no = student.matric_no)
[1495]70if results:
[1498]71    #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
[1495]72    l = []
[1498]73    carry_overs = results
[1986]74
[1770]75    # carry_overs for probation students: yes or not, that is the question
76    #if student.verdict == "C": # on probation
77    #    carry_overs = []
78
[1495]79    for co in carry_overs:
[1856]80        cr_id = "%s_co" % co.CosCode
81        if level.hasObject(cr_id):    #already created
82            continue
[1498]83        carry_over = False
84        query = Eq('code',co.CosCode)
85        c_res = aq_courses(query)
86        if not c_res:
[1845]87            #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode))
[1498]88            continue
89        course_cat_entry = c_res[0]
[1513]90        passmark = getattr(course_cat_entry,'passmark',None)
91        if not passmark:
[1498]92            carry_over = co.GRADE in ('D','E','F')
93        else:
94            try:
95                score = int(co.Score)
96            except:
[1845]97                # logger.info('%s, course %s has invalid score %s"' % (student.id,
98                #                                                     co.CosCode,
99                #                                                     co.Score))
[1498]100                continue
[1571]101            if int(c_res[0].passmark) <= score:
[1498]102                continue
103            carry_over = True
104        if not carry_over:
105            continue
[1495]106        d = context.getCourseInfo(co.CosCode)
107        d['grade'] = co.GRADE
108        d['carry_level'] = co.CarryLevel
109        cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode)
110        course_result = getattr(level,cr_id)
111        context.portal_workflow.doActionFor(course_result,'open')
112        course_result.getContent().edit(mapping=d)
[1856]113        context.waeup_tool.doCommit()
[1811]114#level['create_course_results'](cert_id,current_level)
115res = context.portal_catalog(portal_type="Certificate", id = cert_id)
116l = []
117if res:
118    cert = res[0]
119    path = cert.getPath()
120    #set_trace()
121    query = Eq("path","%s/%s" % (path,current_level)) &\
122            Eq('portal_type','CertificateCourse')
123    courses = aq_portal(query)
124    for c in courses:
[1856]125        cr_id = "%s" % c.getId
126        if level.hasObject(cr_id):    #already created
127            continue
[1811]128        d = context.getCourseInfo(c.getId)
129        cr_id = level.invokeFactory('StudentCourseResult',c.getId)
130        course_result = getattr(level,cr_id)
131        context.portal_workflow.doActionFor(course_result,'open')
[2033]132        #d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
133        d['core_or_elective'] = True
[1811]134        course_result.getContent().edit(mapping=d)
[1856]135        context.waeup_tool.doCommit()
[1823]136logger.info('%s finished to create level %s' % (student.id,current_level))
[2031]137
138if current_session == '05':
139    next_session = '06'
140    next_level = "%s" % (int(current_level) + 100)
141    study_course = getattr(student,'study_course')
142    context.portal_workflow.doActionFor(study_course,'open')
143    study_course_doc = study_course.getContent()
144    study_course_doc.edit(mapping= {'current_level': next_level,
145                                    'current_session': next_session,})
146    context.portal_workflow.doActionFor(study_course,'close_for_edit')
147
[1635]148return response.redirect("%s/%s" % (context.absolute_url(),current_level))
149
Note: See TracBrowser for help on using the repository browser.