Added paging to gallery view.
This commit is contained in:
@@ -28,6 +28,14 @@
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.navigation-icon {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
.mb-2 {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Grid. *
|
||||
****************************************************************************/
|
||||
|
@@ -9,21 +9,17 @@
|
||||
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
|
||||
</head>
|
||||
<body class="background">
|
||||
<div class="centered-container">
|
||||
<a href="/gallery/">
|
||||
<img src="{% static 'imgs/gohome.png' %}">
|
||||
</a>
|
||||
<a href="..">
|
||||
<img src="{% static 'imgs/back.png' %}">
|
||||
</a>
|
||||
</div>
|
||||
{% include 'partials/navigation.html'%}
|
||||
{% if images|length > 0 %}
|
||||
<div class="centered-container">
|
||||
<h1>
|
||||
Files
|
||||
Files ({{num_files}})
|
||||
</h1>
|
||||
</div>
|
||||
<div class="centered-container">
|
||||
<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 %}
|
||||
|
@@ -4,19 +4,12 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, height=device-height" />
|
||||
<title>
|
||||
Vieweing file: {{image_path}}
|
||||
File: {{image_path.name}}
|
||||
</title>
|
||||
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
|
||||
</head>
|
||||
<body class="background">
|
||||
<div class="centered-container">
|
||||
<a href="/gallery/">
|
||||
<img src="{% static 'imgs/gohome.png' %}">
|
||||
</a>
|
||||
<a href="..">
|
||||
<img src="{% static 'imgs/back.png' %}">
|
||||
</a>
|
||||
</div>
|
||||
{% include 'partials/navigation.html'%}
|
||||
<div class="centered-container">
|
||||
<div class="image-container">
|
||||
<a href="{{image_path}}" target="_blank">
|
||||
|
9
viewer/templates/partials/navigation.html
Normal file
9
viewer/templates/partials/navigation.html
Normal file
@@ -0,0 +1,9 @@
|
||||
{% load static %}
|
||||
<div class="centered-container">
|
||||
<a href="/gallery/">
|
||||
<img src="{% static 'imgs/gohome.png' %}" class="navigation-icon">
|
||||
</a>
|
||||
<a href="..">
|
||||
<img src="{% static 'imgs/back.png' %}" class="navigation-icon">
|
||||
</a>
|
||||
</div>
|
@@ -1,5 +1,6 @@
|
||||
# Standard library imports.
|
||||
from pathlib import Path
|
||||
from math import ceil
|
||||
|
||||
# External library imports.
|
||||
import filetype
|
||||
@@ -13,6 +14,14 @@ from django.shortcuts import (render,
|
||||
# Project imports.
|
||||
from .utils import make_thumbnail
|
||||
|
||||
###########################################################################################
|
||||
# CONSTANTS. #
|
||||
###########################################################################################
|
||||
|
||||
CELLS_PER_ROW = 7
|
||||
ROWS_PER_PAGE = 4
|
||||
IMAGES_PER_PAGE = CELLS_PER_ROW * ROWS_PER_PAGE
|
||||
|
||||
###########################################################################################
|
||||
# View functions. #
|
||||
###########################################################################################
|
||||
@@ -23,7 +32,7 @@ def gallery_view(request, path = None):
|
||||
The path should be inside the GALLERY_ROOT path, otherwise a 404 error will be thrown.
|
||||
"""
|
||||
|
||||
def list2rows(lst, cells = 7):
|
||||
def list2rows(lst, cells = CELLS_PER_ROW):
|
||||
rows = []
|
||||
i = 0
|
||||
while i < len(lst):
|
||||
@@ -45,7 +54,14 @@ def gallery_view(request, path = None):
|
||||
images = sorted([i for i in full_path.iterdir() if i.is_file() and filetype.is_image(str(i))])
|
||||
img_data = []
|
||||
|
||||
for image in images:
|
||||
try:
|
||||
page = int(request.GET.get('page', 1)) - 1
|
||||
except ValueError:
|
||||
page = 0
|
||||
|
||||
page_base = IMAGES_PER_PAGE * page
|
||||
|
||||
for image in images[page_base : page_base + IMAGES_PER_PAGE]:
|
||||
make_thumbnail(image)
|
||||
|
||||
img_context = {
|
||||
@@ -57,9 +73,11 @@ def gallery_view(request, path = None):
|
||||
img_data.append(img_context)
|
||||
|
||||
context = {
|
||||
'path': path,
|
||||
'subdirs': list2rows(subdirs),
|
||||
'images': list2rows(img_data)
|
||||
'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)
|
||||
}
|
||||
|
||||
return render(request, 'gallery_view.html', context)
|
||||
|
Reference in New Issue
Block a user