## Script (Python) "folder_factories_target"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST, RESPONSE
##title=A target method that verifies that a type has been chosen.
##

type_name = REQUEST.get('type_name', None)
if not type_name:
    url = context.absolute_url()
    RESPONSE.redirect("%s/folder_factories?portal_status_message=%s"%(url, "You did not select a type.") )
    return
    
    
content_id = REQUEST.get('id', None)
if not content_id:
    content_id = context.portal_topicmanagement.generateRandomId()

if not context.checkIdAvailable(content_id):
    url = context.absolute_url()
    message = """The id "%s" is already in use. (You may have submitted the form twice)"""%content_id
    RESPONSE.redirect("%s/folder_factories?portal_status_message=%s"%(url, message) )
    return
    

return context.invokeFactory(type_name, content_id, RESPONSE=RESPONSE)