##parameters=REQUEST
# $Id: firsttime_login.py 1747 2007-05-07 20:56:24Z joachim $
"""
process the Application Form
return html renderer + psm
"""
import DateTime
from urllib import urlencode
current = DateTime.DateTime()
pr = context.portal_registration

validate = REQUEST.has_key("cpsdocument_create_button")

lt = context.portal_layouts
#pr = context.portal_registration

res,psm,ds = lt.renderLayout(layout_id= 'student_firsttime_login',
                      schema_id= 'student_returning',
                      context=context,
                      mapping=validate and REQUEST,
                      ob={},
                      layout_mode='create',
                      formaction = "firsttime_login",
                      button = "Search",
                      commit=False,
                      )
if psm == 'invalid':
    return context.firsttime_login_form(rendered = res,
                                 psm = "Please correct your input!",
                                 #psm = "%s, %s" % (psm,ds),
                                 firstlayout = True,
                                 lastlayout = True,
                                 ds = ds,
                                 )
elif psm == '':
    return context.firsttime_login_form(rendered = res,
                                 psm = None,
                                 firstlayout = True,
                                 lastlayout = True,
                                 ds = ds,
                                 )
elif psm == 'valid':
    pass
action = "/set_access_data"
args = {}
args['matric_no'] = ds.get('matric_no')
args['name'] = ds.get('student').name
url = context.absolute_url() + action + '?' + urlencode(args)
REQUEST.RESPONSE.redirect(url)
