## Script (Python) "topic_remove_association"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST, RESPONSE
##title=
##
assoclist = REQUEST.get('assoclist', [])
topicmap = context.portal_topicmaps.getTopicMap()
if not assoclist:
    msg = "No associations selected."
else:
    #TODO: Add a removeAssociations method
    for assocserial, roleserial in assoclist:
        assoc = topicmap.getAssociationBySerial(assocserial)
        if assoc is None:
            raise AssertionError, "No association with tm_serial %s"%assocserial
        context.removeAssociation(assoc)
    msg = "%d association(s) successfully removed."%len(assoclist)
    
from Products.PythonScripts.standard import url_quote_plus as url_quote

RESPONSE.redirect("%s?portal_status_message=%s"%(REQUEST.HTTP_REFERER, url_quote(msg)))