##parameters=REQUEST, certid=None
# $Id: refresh_certificate_info.py 1094 2006-12-19 12:11:44Z henrik $
"""
refresh the certificate info in the students_catalog
"""
request = context.REQUEST
if not certid:
    return "Certificate not specified"

course = request.get('certid')
res = context.certificates_catalog(code = course)
if not res:
    return "Certificate %s not found"
faculty = res[0].faculty
department = res[0].department
s_cat = context.students_catalog
s_res = s_cat(course = certid)
#from Products.zdb import set_trace
#set_trace()
if not s_res:
    return "No students for %s not found"
refreshed = []
refreshed.append("Record started")
for student_id in [st.id  for st in s_res]:
    s_cat.modifyRecord(id = student_id,
                       faculty = faculty,
                       department = department,
                       )
    refreshed.append("Record %s refreshed, faculty = %s, department = %s" % (student_id,faculty,department))
return '\r'.join(refreshed)
