Added page navigation buttons to the gallery view.
This commit is contained in:
BIN
viewer/static/imgs/forward.png
Executable file
BIN
viewer/static/imgs/forward.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
@@ -20,24 +20,44 @@
|
||||
<div class="mb-2">
|
||||
{% for page in pages %}<a href="./?page={{page}}">{{page}}</a>{% if not forloop.last %}<span> </span>{% endif %}{% endfor %}
|
||||
</div>
|
||||
<table class="mauto">
|
||||
<tbody>
|
||||
{% for row in images %}
|
||||
<tr>
|
||||
{% for cell in row %}
|
||||
<td class="column">
|
||||
<a href="{{cell.path}}">
|
||||
<img src="{{cell.thumbnail}}">
|
||||
<br>
|
||||
<span>
|
||||
{{cell.path|truncatechars:15}}
|
||||
</span>
|
||||
</a>
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<table class="fc mauto">
|
||||
<tr>
|
||||
{% if page != 1 %}
|
||||
<td class="fc">
|
||||
<a href="./?page={{prev_page}}">
|
||||
<img src="{% static 'imgs/back.png' %}" class="navigation-icon">
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
<td class="fc">
|
||||
<table class="mauto">
|
||||
<tbody>
|
||||
{% for row in images %}
|
||||
<tr>
|
||||
{% for cell in row %}
|
||||
<td class="column">
|
||||
<a href="{{cell.path}}">
|
||||
<img src="{{cell.thumbnail}}">
|
||||
<br>
|
||||
<span>
|
||||
{{cell.path|truncatechars:15}}
|
||||
</span>
|
||||
</a>
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
{% if page != num_pages %}
|
||||
<td class="fc">
|
||||
<a href="./?page={{next_page}}">
|
||||
<img src="{% static 'imgs/forward.png' %}" class="navigation-icon">
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
@@ -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