Added paging to gallery view.
This commit is contained in:
@@ -28,6 +28,14 @@
|
|||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.navigation-icon {
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mb-2 {
|
||||||
|
margin-bottom: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Grid. *
|
* Grid. *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@@ -9,21 +9,17 @@
|
|||||||
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
|
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body class="background">
|
<body class="background">
|
||||||
<div class="centered-container">
|
{% include 'partials/navigation.html'%}
|
||||||
<a href="/gallery/">
|
|
||||||
<img src="{% static 'imgs/gohome.png' %}">
|
|
||||||
</a>
|
|
||||||
<a href="..">
|
|
||||||
<img src="{% static 'imgs/back.png' %}">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
{% if images|length > 0 %}
|
{% if images|length > 0 %}
|
||||||
<div class="centered-container">
|
<div class="centered-container">
|
||||||
<h1>
|
<h1>
|
||||||
Files
|
Files ({{num_files}})
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="centered-container">
|
<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">
|
<table class="mauto">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for row in images %}
|
{% for row in images %}
|
||||||
|
@@ -4,19 +4,12 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, height=device-height" />
|
<meta name="viewport" content="width=device-width, height=device-height" />
|
||||||
<title>
|
<title>
|
||||||
Vieweing file: {{image_path}}
|
File: {{image_path.name}}
|
||||||
</title>
|
</title>
|
||||||
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
|
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body class="background">
|
<body class="background">
|
||||||
<div class="centered-container">
|
{% include 'partials/navigation.html'%}
|
||||||
<a href="/gallery/">
|
|
||||||
<img src="{% static 'imgs/gohome.png' %}">
|
|
||||||
</a>
|
|
||||||
<a href="..">
|
|
||||||
<img src="{% static 'imgs/back.png' %}">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="centered-container">
|
<div class="centered-container">
|
||||||
<div class="image-container">
|
<div class="image-container">
|
||||||
<a href="{{image_path}}" target="_blank">
|
<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.
|
# Standard library imports.
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from math import ceil
|
||||||
|
|
||||||
# External library imports.
|
# External library imports.
|
||||||
import filetype
|
import filetype
|
||||||
@@ -13,6 +14,14 @@ from django.shortcuts import (render,
|
|||||||
# Project imports.
|
# Project imports.
|
||||||
from .utils import make_thumbnail
|
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. #
|
# 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.
|
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 = []
|
rows = []
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(lst):
|
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))])
|
images = sorted([i for i in full_path.iterdir() if i.is_file() and filetype.is_image(str(i))])
|
||||||
img_data = []
|
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)
|
make_thumbnail(image)
|
||||||
|
|
||||||
img_context = {
|
img_context = {
|
||||||
@@ -59,7 +75,9 @@ def gallery_view(request, path = None):
|
|||||||
context = {
|
context = {
|
||||||
'path': path,
|
'path': path,
|
||||||
'subdirs': list2rows(subdirs),
|
'subdirs': list2rows(subdirs),
|
||||||
'images': list2rows(img_data)
|
'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)
|
return render(request, 'gallery_view.html', context)
|
||||||
|
Reference in New Issue
Block a user