'Display visualization based on a username and slug.'

@web.expose
def display_by_username_and_slug(self, trans, username, slug):

    session = trans.sa_session
    user = session.query(model.User).filter_by(username=username).first()
    visualization = trans.sa_session.query(model.Visualization).filter_by(user=user, slug=slug, deleted=False).first()
    if (visualization is None):
        raise web.httpexceptions.HTTPNotFound()
    self.security_check(trans, visualization, check_ownership=False, check_accessible=True)
    user_item_rating = 0
    if trans.get_user():
        user_item_rating = self.get_user_item_rating(trans.sa_session, trans.get_user(), visualization)
        if user_item_rating:
            user_item_rating = user_item_rating.rating
        else:
            user_item_rating = 0
    (ave_item_rating, num_ratings) = self.get_ave_item_rating_data(trans.sa_session, visualization)
    if ((trans.app.visualizations_registry and (visualization.type in trans.app.visualizations_registry.plugins)) and (visualization.type not in trans.app.visualizations_registry.BUILT_IN_VISUALIZATIONS)):
        encoded_visualization_id = trans.security.encode_id(visualization.id)
        return trans.stream_template_mako('visualization/display_in_frame.mako', item=visualization, encoded_visualization_id=encoded_visualization_id, user_item_rating=user_item_rating, ave_item_rating=ave_item_rating, num_ratings=num_ratings, content_only=True)
    visualization_config = self.get_visualization_config(trans, visualization)
    return trans.stream_template_mako('visualization/display.mako', item=visualization, item_data=visualization_config, user_item_rating=user_item_rating, ave_item_rating=ave_item_rating, num_ratings=num_ratings, content_only=True)
