Added previous/next buttons to image view.
This commit is contained in:
@@ -23,12 +23,30 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div class="centered-container">
|
<table class="fc mauto">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{% if prev %}
|
||||||
|
<a href="../{{prev}}">
|
||||||
|
<img src="{% static 'imgs/back.png' %}" class="small-nav-icon">
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
<div class="image-container">
|
<div class="image-container">
|
||||||
<a href="{{image_path}}" target="_blank">
|
<a href="{{image_path}}" target="_blank">
|
||||||
<img src="{{image_path}}" class="image">
|
<img src="{{image_path}}" class="image">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if next %}
|
||||||
|
<a href="../{{next}}">
|
||||||
|
<img src="{% static 'imgs/forward.png' %}" class="small-nav-icon">
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -60,9 +60,9 @@ def gallery_view(request, path = None):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
page_base = IMAGES_PER_PAGE * (page - 1)
|
page_offset = IMAGES_PER_PAGE * (page - 1)
|
||||||
|
|
||||||
for image in images[page_base : page_base + IMAGES_PER_PAGE]:
|
for image in images[page_offset : page_offset + IMAGES_PER_PAGE]:
|
||||||
make_thumbnail(image)
|
make_thumbnail(image)
|
||||||
|
|
||||||
img_context = {
|
img_context = {
|
||||||
@@ -90,7 +90,20 @@ def gallery_view(request, path = None):
|
|||||||
return render(request, 'gallery_view.html', context)
|
return render(request, 'gallery_view.html', context)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return render(request, 'image_view.html', {'image_path': Path('/imgs/').joinpath(path)})
|
image = Path('/imgs/').joinpath(path)
|
||||||
|
img_dir = settings.GALLERY_ROOT.joinpath(path).parent
|
||||||
|
images = sorted([i.name for i in img_dir.iterdir() if i.is_file() and filetype.is_image(str(i))])
|
||||||
|
index = images.index(image.name)
|
||||||
|
previous = index - 1 if index > 0 else None
|
||||||
|
following = index + 1 if index < len(images) - 1 else None
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'image_path': image,
|
||||||
|
'prev': images[previous] if previous is not None else None,
|
||||||
|
'next': images[following] if following is not None else None
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, 'image_view.html', context)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return HttpResponseNotFound('Not found')
|
return HttpResponseNotFound('Not found')
|
||||||
|
Reference in New Issue
Block a user