# Path: simple_cms/contrib/utils.py
# def digg_paginator(records, ADJACENT_PAGES=3, BORDER_PAGES=2, BASE_RANGE=10):
#     pages = []
#     leading = []
#     trailing = []
#     
#     # only 1 set
#     if records.paginator.num_pages <= BASE_RANGE:
#         # be sure to only rock the num of pages
#         if records.paginator.num_pages > 1:
#             pages = xrange(1, records.paginator.num_pages+1)
#     # in the first range, with trailing
#     elif records.paginator.num_pages > BASE_RANGE and records.number < BASE_RANGE+1:
#         pages = xrange(1, BASE_RANGE+1)
#         trailing = xrange(records.paginator.num_pages-BORDER_PAGES+1, records.paginator.num_pages+1)
#     # within the end range
#     elif records.paginator.num_pages - records.number <= ADJACENT_PAGES*2 + 1:
#         leading = xrange(1, BORDER_PAGES+1)
#         pages = xrange(records.paginator.num_pages-(ADJACENT_PAGES*2+1), records.paginator.num_pages+1)
#     else:
#         leading = xrange(1, BORDER_PAGES+1)
#         pages = xrange(records.number - ADJACENT_PAGES, records.number + ADJACENT_PAGES+1)
#         trailing = xrange(records.paginator.num_pages-BORDER_PAGES+1, records.paginator.num_pages+1)
#     
#     return {
#         'pages': pages,
#         'leading': leading,
#         'trailing': trailing,
#     }


from django.views.generic import ListView
from simple_cms.contrib.utils import digg_paginator
                    header['active'] = False
                    pass
                header['href'] = querystring.urlencode()
            except KeyError:
                pass
        return super(DataGridView, self).get(request, *args, **kwargs)
    
    def get_queryset(self):
        queryset = super(DataGridView, self).get_queryset()
        return queryset.order_by(self.sort)
    
    def get_context_data(self, *args, **kwargs):
        context = super(DataGridView, self).get_context_data(*args, **kwargs)
        # operates with use case of a single datagrid per page / view
        # we could abstract that so we could use the sorting logic to return only queryset and variables
        # with a namespace
        context['sort_column'] = self.sort_column
        context['sort_direction'] = self.sort_direction
        # try to find a match
        for header in self.headers:
            if header.get('column') == self.sort_column:
                try:
                    context['sort_column_label'] = header['label']
                except:
                    context['sort_column_label'] = self.sort_column
                break

        context['headers'] = self.headers
        context['querystring'] = self.querystring.urlencode()
        if self.digg:

# Path: simple_cms/contrib/utils.py
# def digg_paginator(records, ADJACENT_PAGES=3, BORDER_PAGES=2, BASE_RANGE=10):
#     pages = []
#     leading = []
#     trailing = []
#     
#     # only 1 set
#     if records.paginator.num_pages <= BASE_RANGE:
#         # be sure to only rock the num of pages
#         if records.paginator.num_pages > 1:
#             pages = xrange(1, records.paginator.num_pages+1)
#     # in the first range, with trailing
#     elif records.paginator.num_pages > BASE_RANGE and records.number < BASE_RANGE+1:
#         pages = xrange(1, BASE_RANGE+1)
#         trailing = xrange(records.paginator.num_pages-BORDER_PAGES+1, records.paginator.num_pages+1)
#     # within the end range
#     elif records.paginator.num_pages - records.number <= ADJACENT_PAGES*2 + 1:
#         leading = xrange(1, BORDER_PAGES+1)
#         pages = xrange(records.paginator.num_pages-(ADJACENT_PAGES*2+1), records.paginator.num_pages+1)
#     else:
#         leading = xrange(1, BORDER_PAGES+1)
#         pages = xrange(records.number - ADJACENT_PAGES, records.number + ADJACENT_PAGES+1)
#         trailing = xrange(records.paginator.num_pages-BORDER_PAGES+1, records.paginator.num_pages+1)
#     
#     return {
#         'pages': pages,
#         'leading': leading,
#         'trailing': trailing,
#     }


# Path: simple_cms/contrib/views.py
from django.views.generic import ListView
from simple_cms.contrib.utils import digg_paginator

                    header['active'] = False
                    pass
                header['href'] = querystring.urlencode()
            except KeyError:
                pass
        return super(DataGridView, self).get(request, *args, **kwargs)
    
    def get_queryset(self):
        queryset = super(DataGridView, self).get_queryset()
        return queryset.order_by(self.sort)
    
    def get_context_data(self, *args, **kwargs):
        context = super(DataGridView, self).get_context_data(*args, **kwargs)
        # operates with use case of a single datagrid per page / view
        # we could abstract that so we could use the sorting logic to return only queryset and variables
        # with a namespace
        context['sort_column'] = self.sort_column
        context['sort_direction'] = self.sort_direction
        # try to find a match
        for header in self.headers:
            if header.get('column') == self.sort_column:
                try:
                    context['sort_column_label'] = header['label']
                except:
                    context['sort_column_label'] = self.sort_column
                break

        context['headers'] = self.headers
        context['querystring'] = self.querystring.urlencode()
        if self.digg:

            context['digg'] = digg_paginator(context['page_obj'])