From 4e98fa0a7f61637f4eebf38d833c0539737e3dd2 Mon Sep 17 00:00:00 2001 From: Oleh-Sali Date: Wed, 18 Nov 2026 14:00:50 +0000 Subject: [PATCH] Fix pagination in spam lists and remove unflag modal from template --- admin/preprints/views.py | 3 +-- admin/templates/preprints/preprint_list.html | 1 - admin_tests/preprints/test_views.py | 25 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/admin/preprints/views.py b/admin/preprints/views.py index 0f38c449c7e..75194bd1f5c 100644 --- a/admin/preprints/views.py +++ b/admin/preprints/views.py @@ -160,7 +160,6 @@ class PreprintSpamList(PermissionRequiredMixin, ListView): SPAM_STATE = SpamStatus.UNKNOWN paginate_by = 25 - paginate_orphans = 1 ordering = 'created' permission_required = ('osf.view_spam', 'osf.view_preprint') raise_exception = True @@ -176,7 +175,7 @@ def get_context_data(self, **kwargs): page_size = self.get_paginate_by(self.object_list) paginator, page, query_set, is_paginated = self.paginate_queryset(self.object_list, page_size) return { - 'preprints': self.object_list, + 'preprints': query_set, 'page': page, } diff --git a/admin/templates/preprints/preprint_list.html b/admin/templates/preprints/preprint_list.html index 12b15547c48..be96b3595c4 100644 --- a/admin/templates/preprints/preprint_list.html +++ b/admin/templates/preprints/preprint_list.html @@ -60,6 +60,5 @@ {% if perms.osf.mark_spam %} {% include 'preprints/spam_modal.html' %} {% include 'preprints/ham_modal.html' %} - {% include 'preprints/unflag_modal.html' %} {% endif %} diff --git a/admin_tests/preprints/test_views.py b/admin_tests/preprints/test_views.py index ff20fa8b7c2..3dbc678251b 100644 --- a/admin_tests/preprints/test_views.py +++ b/admin_tests/preprints/test_views.py @@ -137,6 +137,31 @@ def test_get_known_spam(self, superuser, preprint, ham_preprint, spam_preprint, assert spam_preprint._id in response_ids assert preprint._id not in response_ids + @pytest.mark.parametrize('view_class, url_name, spam_status', [ + (views.PreprintFlaggedSpamList, 'flagged-spam', SpamStatus.FLAGGED), + (views.PreprintKnownSpamList, 'known-spam', SpamStatus.SPAM), + ]) + def test_spam_list_pagination(self, superuser, view_class, url_name, spam_status): + preprints = PreprintFactory.create_batch(26, creator=superuser, finish=False, set_doi=False) + preprint_ids = [preprint.id for preprint in preprints] + Preprint.objects.filter(id__in=preprint_ids).update(spam_status=spam_status) + + request = RequestFactory().get(reverse(f'preprints:{url_name}')) + request.user = superuser + response = view_class.as_view()(request) + + assert response.status_code == 200 + assert [res.id for res in response.context_data['preprints']] == preprint_ids[:25] + assert response.context_data['page'].paginator.num_pages == 2 + + request = RequestFactory().get(reverse(f'preprints:{url_name}'), {'page': 2}) + request.user = superuser + response = view_class.as_view()(request) + + assert response.status_code == 200 + assert [res.id for res in response.context_data['preprints']] == preprint_ids[25:] + assert response.context_data['page'].number == 2 + def test_get_known_ham(self, superuser, preprint, ham_preprint, spam_preprint, flagged_preprint): request = RequestFactory().get(reverse('preprints:known-ham')) request.user = superuser