Skip to content

Commit

Permalink
refactor: Handle the manuscript grid for offsetting the cover
Browse files Browse the repository at this point in the history
  • Loading branch information
hepplerj committed Aug 16, 2024
1 parent 549de64 commit f32ac50
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions denig/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit f32ac50

Please sign in to comment.