## Script (Python) "changeRegState"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST,transition=None
##title=
##
# $Id: epayment_cb.py 1348 2007-01-25 17:06:21Z henrik $
"""
execute transition
"""

mtool = context.portal_membership
member = mtool.getAuthenticatedMember()

#if str(member) not in ('admin','joachim') or transition is None:
#    return 'Forbidden!'
    
if not context.isSectionOfficer() or transition is None:
    return 'Forbidden!'    

import logging
logger = logging.getLogger('Skins.changeRegState')

pm = context.portal_membership
member = pm.getAuthenticatedMember()

request = context.REQUEST
#students = context.portal_url.getPortalObject().campus.students
wftool = context.portal_workflow
student_id = context.getStudentId()
context_doc = context
if student_id is None:
    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
#student = getattr(students,student_id)
#context_doc = student
try:
    wftool.doActionFor(context_doc,transition)
    logger.info('%s executed transition %s for %s' % (member,transition,student_id))
except:
    logger.info('%s tried to execute transition %s for %s, transition not allowed' % (member,transition,student_id))
    return 'Transition not allowed!'

return request.RESPONSE.redirect("%s" % context.absolute_url())
