diff --git a/src/core/views.py b/src/core/views.py index 0b0cb7a..5daba04 100644 --- a/src/core/views.py +++ b/src/core/views.py @@ -13,6 +13,8 @@ from epub2go_web.tasks import getEpub logger = logging.getLogger(__name__) #TODO configure logging books = sorted(get_all_books(), key= lambda b: b.title)# TODO get from pickle +books_count = len(books) +logger.info('Found %s books', books_count) gbnetloc = urlparse(allbooks_url).netloc def index(request: HttpRequest): @@ -33,14 +35,14 @@ def index(request: HttpRequest): return response else: return HttpResponseBadRequest('Input URL invalid.') elif searchParam: - localbooks = [book for book in books if searchParam.lower() in book.title.lower()] + search = searchParam.lower() + localbooks = [book for book in books if search in book.title.lower() or search in book.author.lower()] # 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) @@ -51,7 +53,7 @@ def index(request: HttpRequest): 'title': 'epub2go', 'http_host': f'http://{ request.META['HTTP_HOST'] }', 'page': page, - 'allbooks_count': len(books), + 'allbooks_count': books_count, 'allbooks_url': allbooks_url, } # return base view diff --git a/src/epub2go_web/templates/home.html b/src/epub2go_web/templates/home.html index d7698f5..e8afad9 100644 --- a/src/epub2go_web/templates/home.html +++ b/src/epub2go_web/templates/home.html @@ -5,7 +5,7 @@