## Script (Python) "getClearanceInfo"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# $Id: getClearanceInfo.py 3619 2008-08-08 06:39:00Z henrik $
"""
return Info about the current Student
"""
try:
    from Products.zdb import set_trace
except:
    def set_trace():
        pass
import logging
logger = logging.getLogger('Skins.getClearanceInfo')
from DateTime import DateTime

request = context.REQUEST
mtool = context.portal_membership
wf = context.portal_workflow
member = mtool.getAuthenticatedMember()
member_id = str(member)
path_info = request.get('PATH_INFO').split('/')

# if mtool.isAnonymousUser():
#     return None
# info = {}
# #from Products.zdb import set_trace
# #set_trace()
# requested_id = context.getStudentId()
# if requested_id and not context.isStaff() and member_id != requested_id:
#     logger.info('%s tried to access %s' % (member_id,requested_id))
#     return None
# elif context.isStaff():
#     student_id = requested_id
# else:
#     student_id = member_id

info = context.waeup_tool.getAccessInfo(context)
student_id = info['student_id']
if student_id is None:
    return None

student_record = context.students_catalog.getRecordByKey(student_id)
students_object = context.portal_url.getPortalObject().campus.students
student = getattr(students_object, student_id)
# res = context.portal_catalog(portal_type='Student',id = student_id)
# if len(res) == 0:
#     return None
# creation_date = DateTime(res[0].CreationDate)
# info['penalty'] = creation_date.lessThan(DateTime('2006/12/5'))
info['penalty'] = False
info['id'] = student_id
info['student'] = student
info['student_name'] = student_record.name
#info['review_state'] = context.getStudentReviewState()
info['review_state'] = student_record.review_state
info['app'] = student.application
try:
    info['app_doc'] = student.application.getContent()
except:
    return
info['clear'] = student.clearance
try:
    info['clear_doc'] = student.clearance.getContent()
except:
    return    
info['clear_review_state'] = wf.getInfoFor(student.clearance,'review_state',None)
info['per'] = student.personal
info['per_review_state'] = wf.getInfoFor(student.personal,'review_state',None)
ci = {}
ci['course'] = student_record.course
ci['faculty'] = student_record.faculty
ci['department'] = student_record.department
info['course_doc'] = ci
# if info['review_state'] in ('clearance_requested', 'cleared_and_validated',):
#     info['penalty'] = info['penalty'] and\
#                       info['clear_doc'].entry_date.greaterThan(DateTime('2006/12/30'))
# course = getattr(student,'study_course',None)
# if course:
#     cert_id = course.getContent().study_course
#     res = context.portal_catalog(portal_type = "Certificate", id = cert_id)
#     ci = {}
#     if len(res) > 0:
#         info['course'] = course
#         brain = res[0]
#         ci['study_course'] = brain.getId
#         ci['title'] = brain.Title
#         pl = brain.getPath().split('/')
#         ci['faculty'] = pl[-4]
#         ci['department'] = pl[-3]
#         info['course_doc'] = ci
#     else:
#         info['course'] = None
return info
