Source

django-simplepagination / simplepagination / backends / digg.py

class DiggPaginator(object):

    def paginate(self, frame_size, pages, page_num):
        output = {}
        if page_num > 1:
            output['PREVIOUS'] = page_num -1
        if page_num < pages:
            output['NEXT'] = page_num + 1
        if pages > frame_size and pages <= frame_size +2:
            output['left_page_numbers'] = range(1, pages + 1)
        elif pages <= frame_size:
            output['left_page_numbers'] = range(1, pages + 1)
        elif pages > frame_size and page_num < frame_size - 1:
            output['left_page_numbers'] = range(1, frame_size + 1)
            output['right_page_numbers'] = range(pages -1, pages +1)
        elif pages > frame_size and page_num > frame_size - 2 and pages - (frame_size / 2) <= page_num + 1:
            output['left_page_numbers'] = range(1, 3)
            output['middle_page_numbers'] = range(pages - frame_size + 1, pages +1)
        elif pages > frame_size and page_num > frame_size - 2:
            output['left_page_numbers'] = range(1, 3)
            output['middle_page_numbers'] = range(page_num - (frame_size / 2) +1, page_num + (frame_size / 2))
            output['right_page_numbers'] = range(pages -1, pages +1)
        return output