[2448] | 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 3074 2008-01-31 16:41:48Z henrik $
|
---|
| 9 | """
|
---|
| 10 | process the Application Form
|
---|
| 11 | return html renderer + psm
|
---|
| 12 | """
|
---|
| 13 | request = context.REQUEST
|
---|
| 14 | import DateTime,logging
|
---|
| 15 | try:
|
---|
| 16 | from Products.zdb import set_trace
|
---|
| 17 | except:
|
---|
| 18 | def set_trace():
|
---|
| 19 | pass
|
---|
| 20 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
| 21 | try:
|
---|
| 22 | aq_portal = context.portal_catalog.evalAdvancedQuery
|
---|
| 23 | except:
|
---|
| 24 | aq_portal = context.portal_catalog_real.evalAdvancedQuery
|
---|
| 25 | aq_courses = context.courses_catalog.evalAdvancedQuery
|
---|
| 26 |
|
---|
| 27 | import logging
|
---|
| 28 | logger = logging.getLogger('Skins.refresh_level')
|
---|
| 29 |
|
---|
| 30 | from urllib import urlencode
|
---|
| 31 |
|
---|
| 32 | current = DateTime.DateTime()
|
---|
| 33 | request = context.REQUEST
|
---|
| 34 | #session = request.SESSION
|
---|
| 35 | response = request.RESPONSE
|
---|
| 36 | redirect = response.redirect
|
---|
| 37 | logger = logging.getLogger('Skins.refresh_level')
|
---|
| 38 | mtool = context.portal_membership
|
---|
| 39 | member = mtool.getAuthenticatedMember()
|
---|
| 40 | member_id = str(member)
|
---|
| 41 | wt = context.waeup_tool
|
---|
| 42 | student = context.students_catalog(id=context.getStudentId())[0]
|
---|
| 43 | cert_id = student.course
|
---|
[2460] | 44 | student_id = context.getStudentId()
|
---|
[2448] | 45 | level = context
|
---|
[2460] | 46 | level_id = context.getId()
|
---|
[2448] | 47 | res = context.portal_catalog(portal_type="Certificate", id = cert_id)
|
---|
[2460] | 48 | query = Eq('student_id',student_id) & Eq('level_id', level_id)
|
---|
[2758] | 49 | existing_courses = [course.code for course in
|
---|
[2460] | 50 | context.course_results.evalAdvancedQuery(query)]
|
---|
[2448] | 51 | l = []
|
---|
[2460] | 52 | records = []
|
---|
[2448] | 53 | if res:
|
---|
| 54 | cert = res[0]
|
---|
| 55 | path = cert.getPath()
|
---|
[3074] | 56 | if int(student.level) > 0:
|
---|
| 57 | academics_level = 100 * (int(student.level)/100)
|
---|
| 58 | else:
|
---|
| 59 | academics_level = '000'
|
---|
[2758] | 60 | query = Eq("path","%s/%s" % (path,academics_level)) &\
|
---|
[2448] | 61 | Eq('portal_type','CertificateCourse')
|
---|
| 62 | courses = aq_portal(query)
|
---|
[2460] | 63 | course_ids = [c.getId for c in courses if c.getId not in existing_courses]
|
---|
[2448] | 64 | for course_id in course_ids:
|
---|
| 65 | #set_trace()
|
---|
[2460] | 66 | if course_id in l:
|
---|
| 67 | # don't add twice
|
---|
| 68 | continue
|
---|
| 69 | l += course_id,
|
---|
[2448] | 70 | d = context.getCourseInfo(course_id)
|
---|
| 71 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
|
---|
| 72 | d['course_id'] = course_id
|
---|
[2758] | 73 | d['student_id'] = student_id
|
---|
| 74 | d['level_id'] = level_id
|
---|
[2448] | 75 | d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
|
---|
[2460] | 76 | records.append(d)
|
---|
| 77 | if records:
|
---|
| 78 | context.course_results.addMultipleRecords(records)
|
---|
| 79 |
|
---|
[2448] | 80 | #session.set('in_progress','finished')
|
---|
| 81 | logger.info('%s updated course list' % member)
|
---|
| 82 |
|
---|
| 83 | args = {}
|
---|
| 84 | psm = "Course list updated!"
|
---|
| 85 | args['portal_status_message'] = psm
|
---|
| 86 | if action_after_validate:
|
---|
| 87 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
|
---|
| 88 | else:
|
---|
| 89 | url = context.absolute_url() + '?' + urlencode(args)
|
---|
[2758] | 90 | return REQUEST.RESPONSE.redirect(url) |
---|