From f32ac50176e82160209aa27970a603f97cb76987 Mon Sep 17 00:00:00 2001 From: Jason Heppler Date: Fri, 16 Aug 2024 10:46:44 -0500 Subject: [PATCH] refactor: Handle the manuscript grid for offsetting the cover --- denig/views.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/denig/views.py b/denig/views.py index 1db641b..8a96981 100644 --- a/denig/views.py +++ b/denig/views.py @@ -46,16 +46,31 @@ class DocumentListView(generic.ListView): model = Document context_object_name = "document_list" template_name = "manuscript.html" - paginate_by = 13 + paginate_by = 12 + + def paginate_queryset(self, queryset, page_size): + """ + Custom paginate queryset to handle the offset on page 2. + """ + paginator = super().get_paginator(queryset, page_size) + page = self.request.GET.get("page") + if page is None or page == "1": + # For the first page, we want 13 items (cover + 12 manuscript pages) + page_obj = paginator.page(1) + page_obj.object_list = queryset[:13] + else: + # For subsequent pages, ensure no overlap + page_number = paginator.validate_number(page) + start_index = 13 + (page_number - 2) * page_size + end_index = start_index + page_size + page_obj = paginator.page(page_number) + page_obj.object_list = queryset[start_index:end_index] + return (paginator, page_obj, page_obj.object_list, page_obj.has_other_pages()) def get_queryset(self): - # This method ensures the documents are ordered by 'document_id' + # Ensures the documents are ordered by 'document_id' return Document.objects.all().order_by("document_id") - def get_absolute_url(self): - """Return the URL for this document.""" - return reverse("document", args=[str(self.id)]) - def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) page_obj = context.get("page_obj")