Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/journal/tests/test_journal_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,69 @@ def test_issue_page(self):
self.assertContains(response, "Volume 4")
self.assertContains(response, self.article_title)

def test_issue_sections_context_is_not_paginated(self):
first_section = self.published_article.section
second_section = helpers.create_section(
self.journal,
name="Review",
plural="Reviews",
sequence=999,
)
unpublished_section = helpers.create_section(
self.journal,
name="Draft",
plural="Drafts",
sequence=1000,
)

for num in range(50):
article = helpers.create_article(
journal=self.journal,
title=f"Extra issue article {num}",
stage="Published",
section=first_section,
date_published=timezone.now(),
)
self.issue.articles.add(article)

second_section_article = helpers.create_article(
journal=self.journal,
title="Second section article",
stage="Published",
section=second_section,
date_published=timezone.now(),
)
self.issue.articles.add(second_section_article)

unpublished_article = helpers.create_article(
journal=self.journal,
title="Unpublished section article",
stage="Unassigned",
section=unpublished_section,
)
self.issue.articles.add(unpublished_article)

response = self.client.get(
reverse(
"journal_issue",
kwargs={
"issue_id": self.issue.pk,
},
),
SERVER_NAME=self.journal_domain,
)

article_page_sections = {
article.section for article in response.context["articles"]
}
self.assertIn(first_section, article_page_sections)
self.assertNotIn(second_section, article_page_sections)

self.assertEqual(
response.context["issue_sections"],
[first_section, second_section],
)

def test_become_reviewer_page(self):
self.client.force_login(
self.new_user,
Expand Down
12 changes: 11 additions & 1 deletion src/journal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,17 @@ def issue(request, issue_id, show_sidebar=True):
date__lte=timezone.now(),
)

sorted_articles = issue_object.get_sorted_articles()
issue_sections = []
seen_section_ids = set()

for article in sorted_articles:
if article.section_id not in seen_section_ids:
issue_sections.append(article.section)
seen_section_ids.add(article.section_id)

page = request.GET.get("page", 1)
paginator = Paginator(issue_object.get_sorted_articles(), 50)
paginator = Paginator(sorted_articles, 50)

try:
articles = paginator.page(page)
Expand Down Expand Up @@ -373,6 +382,7 @@ def issue(request, issue_id, show_sidebar=True):
"issues": issue_objects,
"structure": issue_object.structure, # for backwards compatibility
"articles": articles,
"issue_sections": issue_sections,
"editors": editors,
"show_sidebar": show_sidebar,
}
Expand Down