Added page navigation buttons to the gallery view.
This commit is contained in:
@@ -53,13 +53,14 @@ def gallery_view(request, path = None):
|
||||
subdirs = sorted([i for i in full_path.iterdir() if i.is_dir()])
|
||||
images = sorted([i for i in full_path.iterdir() if i.is_file() and filetype.is_image(str(i))])
|
||||
img_data = []
|
||||
num_pages = ceil((len(images) / CELLS_PER_ROW) / ROWS_PER_PAGE)
|
||||
|
||||
try:
|
||||
page = int(request.GET.get('page', 1)) - 1
|
||||
page = int(request.GET.get('page', 1))
|
||||
except ValueError:
|
||||
page = 0
|
||||
page = 1
|
||||
|
||||
page_base = IMAGES_PER_PAGE * page
|
||||
page_base = IMAGES_PER_PAGE * (page - 1)
|
||||
|
||||
for image in images[page_base : page_base + IMAGES_PER_PAGE]:
|
||||
make_thumbnail(image)
|
||||
@@ -72,12 +73,18 @@ def gallery_view(request, path = None):
|
||||
|
||||
img_data.append(img_context)
|
||||
|
||||
print(page)
|
||||
|
||||
context = {
|
||||
'path': path,
|
||||
'subdirs': list2rows(subdirs),
|
||||
'images': list2rows(img_data),
|
||||
'pages': range(1, ceil((len(images) / CELLS_PER_ROW) / ROWS_PER_PAGE) + 1),
|
||||
'num_files': len(images)
|
||||
'pages': range(1, num_pages + 1),
|
||||
'num_files': len(images),
|
||||
'page': page,
|
||||
'prev_page': page - 1,
|
||||
'next_page': page + 1,
|
||||
'num_pages': num_pages
|
||||
}
|
||||
|
||||
return render(request, 'gallery_view.html', context)
|
||||
|
Reference in New Issue
Block a user