[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 5163 2010-04-21 04:38:00Z henrik $
|
---|
| 9 | """
|
---|
| 10 | """
|
---|
| 11 | request = context.REQUEST
|
---|
| 12 | import DateTime,logging
|
---|
| 13 | try:
|
---|
| 14 | from Products.zdb import set_trace
|
---|
| 15 | except:
|
---|
| 16 | def set_trace():
|
---|
| 17 | pass
|
---|
| 18 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
| 19 | try:
|
---|
| 20 | aq_portal = context.portal_catalog.evalAdvancedQuery
|
---|
| 21 | except:
|
---|
| 22 | aq_portal = context.portal_catalog_real.evalAdvancedQuery
|
---|
| 23 | aq_courses = context.courses_catalog.evalAdvancedQuery
|
---|
| 24 |
|
---|
| 25 | import logging
|
---|
| 26 | logger = logging.getLogger('Skins.refresh_level')
|
---|
| 27 |
|
---|
| 28 | from urllib import urlencode
|
---|
| 29 |
|
---|
| 30 | current = DateTime.DateTime()
|
---|
| 31 | request = context.REQUEST
|
---|
| 32 | #session = request.SESSION
|
---|
| 33 | response = request.RESPONSE
|
---|
| 34 | redirect = response.redirect
|
---|
| 35 | logger = logging.getLogger('Skins.refresh_level')
|
---|
| 36 | mtool = context.portal_membership
|
---|
| 37 | member = mtool.getAuthenticatedMember()
|
---|
| 38 | member_id = str(member)
|
---|
| 39 | wt = context.waeup_tool
|
---|
| 40 | student = context.students_catalog(id=context.getStudentId())[0]
|
---|
| 41 | cert_id = student.course
|
---|
[2460] | 42 | student_id = context.getStudentId()
|
---|
[2448] | 43 | level = context
|
---|
[2460] | 44 | level_id = context.getId()
|
---|
[5144] | 45 | session_id = context.getLevelSession(level.getContent(),student_id,level_id)
|
---|
[2448] | 46 | res = context.portal_catalog(portal_type="Certificate", id = cert_id)
|
---|
[2460] | 47 | query = Eq('student_id',student_id) & Eq('level_id', level_id)
|
---|
[2758] | 48 | existing_courses = [course.code for course in
|
---|
[2460] | 49 | context.course_results.evalAdvancedQuery(query)]
|
---|
[2448] | 50 | l = []
|
---|
[2460] | 51 | records = []
|
---|
[2448] | 52 | if res:
|
---|
| 53 | cert = res[0]
|
---|
| 54 | path = cert.getPath()
|
---|
[3074] | 55 | if int(student.level) > 0:
|
---|
| 56 | academics_level = 100 * (int(student.level)/100)
|
---|
| 57 | else:
|
---|
| 58 | academics_level = '000'
|
---|
[2758] | 59 | query = Eq("path","%s/%s" % (path,academics_level)) &\
|
---|
[2448] | 60 | Eq('portal_type','CertificateCourse')
|
---|
| 61 | courses = aq_portal(query)
|
---|
[2460] | 62 | course_ids = [c.getId for c in courses if c.getId not in existing_courses]
|
---|
[2448] | 63 | for course_id in course_ids:
|
---|
| 64 | #set_trace()
|
---|
[2460] | 65 | if course_id in l:
|
---|
| 66 | # don't add twice
|
---|
| 67 | continue
|
---|
| 68 | l += course_id,
|
---|
[2448] | 69 | d = context.getCourseInfo(course_id)
|
---|
| 70 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
|
---|
| 71 | d['course_id'] = course_id
|
---|
[2758] | 72 | d['student_id'] = student_id
|
---|
| 73 | d['level_id'] = level_id
|
---|
[5144] | 74 | d['session_id'] = session_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')
|
---|
[5144] | 81 | logger.info('%s updated level %s of %s' % (member,level_id,student_id))
|
---|
[2448] | 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) |
---|