diff --git a/src/core/views.py b/src/core/views.py
index 8fdf636..f605345 100644
--- a/src/core/views.py
+++ b/src/core/views.py
@@ -1,5 +1,6 @@
from django.shortcuts import render
from django.http import HttpRequest, HttpResponse, FileResponse, HttpResponseBadRequest
+from django.core.paginator import Paginator
from epub2go.convert import get_all_books, Book, allbooks_url
@@ -34,16 +35,26 @@ def index(request: HttpRequest):
elif searchParam:
localbooks = [book for book in books if searchParam in book.title]
- # return base view
- # TODO pagination
+ # paginate items
+ paginationParam = request.GET.get('p', '')
+ try:
+ pageNo = int(paginationParam)
+ except ValueError:
+ logger.error('Failed to cast %s to int', paginationParam)
+ pageNo = 1
+
+ pages = Paginator(localbooks, 100)
+ if pageNo < 1 or pageNo > pages.num_pages:
+ pageNo = 1
+ page = pages.page(pageNo)
context = {
'title': 'epub2go',
'http_host': f'http://{ request.META['HTTP_HOST'] }',
- 'books': localbooks,
- 'books_count': len(localbooks),
+ 'page': page,
'allbooks_count': len(books),
'allbooks_url': allbooks_url,
}
+ # return base view
return render(request, 'home.html', context)
def validateUrl(param)->bool :
diff --git a/src/epub2go_web/static/styles.css b/src/epub2go_web/static/styles.css
index e9e5c7f..53f7c36 100644
--- a/src/epub2go_web/static/styles.css
+++ b/src/epub2go_web/static/styles.css
@@ -18,6 +18,8 @@ body{
font-size:18px;
color:var(--fg);
padding:0 .2em;
+ text-align: center;
+ justify-content: center;
}
h1,h2,h3{
@@ -84,4 +86,7 @@ a:hover, a:any-link{
min-height: 1em;
height: 100%;
padding: 1px;
+}
+.pagination a{
+ padding-left: 2em;
}
\ No newline at end of file
diff --git a/src/epub2go_web/templates/home.html b/src/epub2go_web/templates/home.html
index 021e235..44fb1ef 100644
--- a/src/epub2go_web/templates/home.html
+++ b/src/epub2go_web/templates/home.html
@@ -16,7 +16,7 @@
-
+ {{ page.paginator.count }} Ergebnisse gefunden:
| @@ -45,6 +45,17 @@ {% endfor %} |