source: WAeUP_SRP/trunk/skins/waeup_student/refresh_level.py @ 2067

Last change on this file since 2067 was 2040, checked in by joachim, 17 years ago

don't add existing course

  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1## Script (Python) "refresh_level"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=REQUEST=None, student=None, action_after_reject=None, action_after_validate=None
8# $Id: refresh_level.py 2040 2007-07-20 11:05:34Z joachim $
9"""
10process the Application Form
11return html renderer + psm
12"""
13request = context.REQUEST
14import DateTime,logging
15try:
16    from Products.zdb import set_trace
17except:
18    def set_trace():
19        pass
20from Products.AdvancedQuery import Eq, Between, Le,In
21try:
22    aq_portal = context.portal_catalog.evalAdvancedQuery
23except:
24    aq_portal = context.portal_catalog_real.evalAdvancedQuery
25aq_courses = context.courses_catalog.evalAdvancedQuery
26
27import logging
28logger = logging.getLogger('Skins.refresh_level')
29
30from urllib import urlencode
31
32current = DateTime.DateTime()
33request = context.REQUEST
34#session = request.SESSION
35response = request.RESPONSE
36redirect = response.redirect
37logger = logging.getLogger('Skins.refresh_level')
38mtool = context.portal_membership
39member = mtool.getAuthenticatedMember()
40member_id = str(member)
41wt = context.waeup_tool
42student = context.students_catalog(id=context.getStudentId())[0]
43cert_id = student.course
44current_level = student.level
45level = context
46#results = context.results_import(matric_no = student.matric_no)
47# results = False #skip carry overs
48# if results:
49#     #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
50#     l = []
51#     carry_overs = results
52#     for co in carry_overs:
53#         carry_over = False
54#         query = Eq('code',co.CosCode)
55#         c_res = aq_courses(query)
56#         if not c_res:
57#             logger.info('%s, course %s not found in courses_catalog' % (student.id,co.CosCode))
58#             continue
59#         course_cat_entry = c_res[0]
60#         if not course_cat_entry.passmark:
61#             carry_over = co.GRADE in ('D','E','F')
62#         else:
63#             try:
64#                 score = int(co.Score)
65#             except:
66#                 logger.info('%s, course %s has invalid score %s' % (student.id,
67#                                                                     co.CosCode,
68#                                                                     co.Score))
69#                 continue
70#             if int(c_res[0].passmark) <= score:
71#                 continue
72#             carry_over = True
73#         if not carry_over:
74#             continue
75#         d = context.getCourseInfo(co.CosCode)
76#         d['grade'] = co.GRADE
77#         d['carry_level'] = co.CarryLevel
78#         course_id = "%s_co" % co.CosCode
79#         if not context.hasObject(course_id):
80#             cr_id = level.invokeFactory('StudentCourseResult',course_id)
81#             course_result = getattr(level,cr_id)
82#             context.portal_workflow.doActionFor(course_result,'open')
83#             course_result.getContent().edit(mapping=d)
84res = context.portal_catalog(portal_type="Certificate", id = cert_id)
85l = []
86if res:
87    cert = res[0]
88    path = cert.getPath()
89    query = Eq("path","%s/%s" % (path,student.level)) &\
90            Eq('portal_type','CertificateCourse')
91    courses = aq_portal(query)
92    course_ids = [c.getId  for c in courses if c.getId not in level.objectIds()]
93    for c_id in course_ids:
94        #set_trace()
95        d = context.getCourseInfo(c_id)
96        cr_id = level.invokeFactory('StudentCourseResult',c_id)
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)
101        context.waeup_tool.doCommit()
102#session.set('in_progress','finished')
103logger.info('%s updated course list' % member)
104
105args = {}
106psm = "Course list updated!"
107args['portal_status_message'] = psm
108if action_after_validate:
109    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
110else:
111    url = context.absolute_url() + '?' + urlencode(args)
112return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.