def get_context(self, page, range_gap=5):
        try:
            page = int(page)
        except (ValueError, __HOLE__), exc:
            raise InvalidPage, exc
        
        try:
            paginator = self.page(page)
        except EmptyPage:
            return {
                'EMPTY_PAGE': True,
            }
        
        if page > 5:
            start = page-range_gap
        else:
            start = 1

        if page < self.num_pages-range_gap:
            end = page+range_gap+1
        else:
            end = self.num_pages+1

        context = {
            'page_range': range(start, end),
            'objects': paginator.object_list,
            'num_pages': self.num_pages,
            'page': page,
            'has_pages': self.num_pages > 1,
            'has_previous': paginator.has_previous(),
            'has_next': paginator.has_next(),
            'previous_page': paginator.previous_page_number() if paginator.has_previous() else None,
            'next_page': paginator.next_page_number() if paginator.has_next() else None,
            'is_first': page == 1,
            'is_last': page == self.num_pages,
        }
        
        return context
dataset/ETHPy150Open dcramer/django-paging/paging/paginators.py/BetterPaginator.get_context