'Display history 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()
    history = trans.sa_session.query(model.History).options(eagerload('tags')).options(eagerload('annotations')).filter_by(user=user, slug=slug, deleted=False).first()
    if (history is None):
        raise web.httpexceptions.HTTPNotFound()
    self.history_manager.error_unless_accessible(history, trans.user, current_history=trans.history)
    user_item_rating = 0
    if trans.get_user():
        user_item_rating = self.get_user_item_rating(trans.sa_session, trans.get_user(), history)
        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, history)
    user_is_owner = (trans.user == history.user)
    history_dictionary = self.history_serializer.serialize_to_view(history, view='dev-detailed', user=trans.user, trans=trans)
    history_dictionary['annotation'] = self.get_item_annotation_str(trans.sa_session, history.user, history)
    return trans.stream_template_mako('history/display.mako', item=history, item_data=[], user_is_owner=user_is_owner, history_dict=history_dictionary, user_item_rating=user_item_rating, ave_item_rating=ave_item_rating, num_ratings=num_ratings)
