'Gets or creates a default history and associates it with the current
session.'

def get_or_create_default_history(self):

    if (not self.galaxy_session.user):
        return self.new_history()
    unnamed_histories = self.sa_session.query(self.app.model.History).filter_by(user=self.galaxy_session.user, name=self.app.model.History.default_name, deleted=False)
    default_history = None
    for history in unnamed_histories:
        if (len(history.datasets) == 0):
            default_history = history
            break
    if default_history:
        history = default_history
        self.set_history(history)
    else:
        history = self.new_history()
    return history
