## Script (Python) "create_helptext"
##bind container=container
##bind context=context
##bind namespace=_
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST, RESPONSE
##title=Create a helptext occurrence on a topic.
##
topicmap = context.portal_topicmaps.getTopicMap()
helptextPSI = 'http://psi.emnekart.no/ztm/ztmdefault/#helptext'
helptext = topicmap.getTopicBySubjectIdentifier(helptextPSI)
if helptext is None:
    raise AssertionError("Unable to find topic with SI: %s"%(helptextPSI))
generateRandomId = context.portal_topicmanagement.generateRandomId
occid = generateRandomId()
while not context.checkIdAvailable(occid):
    occid = generateRandomId()
context.invokeFactory(id=occid, type_name='Occurrence')
occurrence = getattr(context, occid)
occurrence.setType(helptext)
occurrence.setData('Fill in helptext for %s. Add the a topictype as scope for specialize the text.'%context.Title())
RESPONSE.redirect(occurrence.absolute_url() + '/' + occurrence.getTypeInfo().getActionById('ztmedit'))
