##// END OF EJS Templates
Add random images list view
Add random images list view

File last commit:

r1200:570dd244 default
r1246:306250a6 default
Show More
paginator.py
61 lines | 1.5 KiB | text/x-python | PythonLexer
neko259
Code cleanup part 2
r722 __author__ = 'neko259'
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596
neko259
Code cleanup part 2
r722 from django.core.paginator import Paginator
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596
neko259
Divided paginator with page range
r1199 PAGINATOR_LOOKAROUND_SIZE = 2
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596
def get_paginator(*args, **kwargs):
return DividedPaginator(*args, **kwargs)
class DividedPaginator(Paginator):
lookaround_size = PAGINATOR_LOOKAROUND_SIZE
current_page = 0
neko259
Pretty divided paginator with ellipsis
r1200 def _left_range(self):
neko259
Divided paginator with page range
r1199 return self.page_range[:self.lookaround_size]
neko259
Pretty divided paginator with ellipsis
r1200 def _right_range(self):
neko259
Divided paginator with page range
r1199 pages = self.num_pages-self.lookaround_size
if pages <= 0:
return []
else:
return self.page_range[pages:]
neko259
Pretty divided paginator with ellipsis
r1200 def _center_range(self):
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 index = self.page_range.index(self.current_page)
neko259
Divided paginator with page range
r1199 start = max(self.lookaround_size, index - self.lookaround_size)
end = min(self.num_pages - self.lookaround_size, index + self.lookaround_size + 1)
return self.page_range[start:end]
neko259
Pretty divided paginator with ellipsis
r1200 def get_divided_range(self):
neko259
Divided paginator with page range
r1199 dr = list()
neko259
Pretty divided paginator with ellipsis
r1200 dr += self._left_range()
dr += self._center_range()
dr += self._right_range()
neko259
Divided paginator with page range
r1199
# Remove duplicates
dr = list(set(dr))
dr.sort()
return dr
neko259
Pretty divided paginator with ellipsis
r1200 def get_dividers(self):
dividers = []
prev_page = 1
for page in self.get_divided_range():
if page - prev_page > 1:
dividers.append(page)
neko259
Divided paginator with page range
r1199
neko259
Pretty divided paginator with ellipsis
r1200 # There can be no more than 2 dividers, so don't bother going
# further
if len(dividers) > 2:
break
prev_page = page
neko259
Divided paginator with page range
r1199
neko259
Pretty divided paginator with ellipsis
r1200 return dividers