'Import a visualization into user\'s workspace.'

@web.expose
@web.require_login('share    Galaxy    visualizations')
def imp(self, trans, id):

    referer = trans.request.referer
    if referer:
        referer_message = ("<a    href='%s'>return    to    the    previous    page</a>" % escape(referer))
    else:
        referer_message = ("<a    href='%s'>go    to    Galaxy's    start    page</a>" % web.url_for('/'))
    session = trans.sa_session
    visualization = self.get_visualization(trans, id, check_ownership=False)
    if (visualization.importable is False):
        return trans.show_error_message(('The    owner    of    this    visualization    has    disabled    imports    via    this    link.<br>You    can    %s' % referer_message), use_panels=True)
    elif visualization.deleted:
        return trans.show_error_message(("You    can't    import    this    visualization    because    it    has    been    deleted.<br>You    can    %s" % referer_message), use_panels=True)
    else:
        imported_visualization = visualization.copy(user=trans.user, title=('imported:    ' + visualization.title))
        session = trans.sa_session
        session.add(imported_visualization)
        session.flush()
        return trans.show_ok_message(message=('Visualization    "%s"    has    been    imported.    <br>You    can    <a    href="%s">start    using    this    visualization</a>    or    %s.' % (visualization.title, web.url_for(controller='visualization'), referer_message)), use_panels=True)
