def get_centered_pagination(current, total, visible=5):
    """ Return the range of pages to render in a pagination menu.

        The current page is always kept in the middle except
        for the edge cases.

        Reeturns a dict
            { prev, first, current, last, next }

        :param current: the current page
        :param total: total number of pages available
        :param visible: number of pages visible
    """
    inc = visible / 2
    first = current - inc
    last = current + inc
    if total <= visible:
        first = 1
        last = total
    elif last > total:
        first = total - (visible - 1)
        last = total
    elif first < 1:
        first = 1
        last = visible
    return dict(prev=current - 1 if current > 1 else None, first=first,
        current=current, last=last, next=current + 1 if current < total else
        None)
