## Script (Python) "personal_edit"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST, cpsdocument_edit_button=None, cpsdocument_edit_and_view_button=None, action=None
##title=
# $Id: application_edit.py 1071 2006-12-16 15:53:13Z joachim $
"""
"""
wftool = context.portal_workflow
from urllib import urlencode
from Products.CPSDocument.utils import getFormUidUrlArg
import DateTime
current = DateTime.DateTime()
import logging
logger = logging.getLogger('Student.Personal.Edit')

info = context.getPersonalInfo()

if info is None:
    logger.info('"anonymous access","%s"' % REQUEST.get('URL0'))
    return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())

student = info['student']
per = info['per']
per_doc = info['per_doc']
state = info['review_state']
is_valid, ds = per_doc.validate(request=REQUEST,
                                schema_id = 'student_personal',
                                layout_id = 'student_personal_fe',
                                proxy=per,
                                use_session=True)

psm = ""
args = {}
action = "/personal_edit_form"
base_url = per.absolute_url()

if is_valid:
    if cpsdocument_edit_button:
        logger.info('"%s", "edited personal data"' % (info['id']))
        #action = ""
        #base_url = student.absolute_url()
        #url = base_url + action
        psm = 'psm_content_changed'
else:
    psm = 'psm_content_error'
    args = getFormUidUrlArg(REQUEST)

args['portal_status_message'] = psm
url = base_url + action + '?' + urlencode(args)
REQUEST.RESPONSE.redirect(url)
