From e946e54c4a54f1fca22441ceaf1cc416c2839844 Mon Sep 17 00:00:00 2001 From: Vipul Narang Date: Wed, 4 Sep 2024 21:09:19 +0530 Subject: [PATCH 1/8] List per page added to request param infolderadmin --- CHANGELOG.rst | 4 ++++ djangocms_versioning_filer/monkeypatch/admin/folderadmin.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4f34327..f5600a6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,10 @@ Changelog ========= +Unreleased +========== +* list per page added to folderadmin to read from request parameters + 1.3.0 (2024-05-16) ========== * Django 4.2 support added diff --git a/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py b/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py index f1e69cb..43eebc9 100644 --- a/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py +++ b/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py @@ -203,7 +203,9 @@ def directory_listing(self, request, folder_id=None, viewtype=None): permissions = {} items = folder_children + folder_files - paginator = Paginator(items, filer.settings.FILER_PAGINATE_BY) + list_per_page = request.GET.get('list_per_page') + paginator_count = list_per_page or filer.settings.FILER_PAGINATE_BY + paginator = Paginator(items, paginator_count) # Are we moving to clipboard? if request.method == 'POST' and '_save' not in request.POST: From 0381338d878742185ddb9ed1b58fc30a86cb9b03 Mon Sep 17 00:00:00 2001 From: Vipul Narang Date: Thu, 5 Sep 2024 13:16:24 +0530 Subject: [PATCH 2/8] corrected approach to use int --- djangocms_versioning_filer/monkeypatch/admin/folderadmin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py b/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py index 43eebc9..5c8b5b3 100644 --- a/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py +++ b/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py @@ -204,7 +204,7 @@ def directory_listing(self, request, folder_id=None, viewtype=None): items = folder_children + folder_files list_per_page = request.GET.get('list_per_page') - paginator_count = list_per_page or filer.settings.FILER_PAGINATE_BY + paginator_count = int(list_per_page) if list_per_page else filer.settings.FILER_PAGINATE_BY paginator = Paginator(items, paginator_count) # Are we moving to clipboard? From 345c9b7f1852e93560a52d239c543405e268a778 Mon Sep 17 00:00:00 2001 From: Vipul Narang Date: Thu, 5 Sep 2024 13:19:33 +0530 Subject: [PATCH 3/8] adding required comment --- djangocms_versioning_filer/monkeypatch/admin/folderadmin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py b/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py index 5c8b5b3..b9271d0 100644 --- a/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py +++ b/djangocms_versioning_filer/monkeypatch/admin/folderadmin.py @@ -203,6 +203,7 @@ def directory_listing(self, request, folder_id=None, viewtype=None): permissions = {} items = folder_children + folder_files + # Get list_per_page from request params else use default value list_per_page = request.GET.get('list_per_page') paginator_count = int(list_per_page) if list_per_page else filer.settings.FILER_PAGINATE_BY paginator = Paginator(items, paginator_count) From 5e3c972eaff69c4ea1a712ab52716b8dde449620 Mon Sep 17 00:00:00 2001 From: Vipul Narang Date: Wed, 18 Sep 2024 16:32:08 +0530 Subject: [PATCH 4/8] added tests --- tests/test_admin.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/test_admin.py b/tests/test_admin.py index 5f2e82a..8a5869d 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -1,7 +1,14 @@ +from cms.test_utils.testcases import CMSTestCase + from django.shortcuts import reverse +from django.test import TestCase, RequestFactory +from django.contrib.auth.models import User +from django.core.paginator import Paginator from djangocms_versioning.helpers import proxy_model -from filer.models import File + +from filer.models import File, Folder +from filer.admin.folderadmin import FolderAdmin from tests.base import BaseFilerVersioningTestCase @@ -55,3 +62,26 @@ def test_admin_edit_button_disabled(self): self.assertContains(response, "js-versioning-action-btn") self.assertContains(response, "js-versioning-action") self.assertContains(response, "inactive") + + +class FolderAdminTestCase(TestCase): + def setUp(self): + self.factory = RequestFactory() + self.user = User.objects.create(username='testuser', password='12345') + self.folder = Folder.objects.create(name='Test Folder', owner=self.user) + self.file1 = File.objects.create(name='Test File 1', folder=self.folder, owner=self.user) + self.file2 = File.objects.create(name='Test File 2', folder=self.folder, owner=self.user) + + def test_list_per_page_from_request(self): + # Simulate a Get request with list_per_page parameter + request = self.factory.get('/', {'list_per_page': '1'}) + request.user = self.user + + request.GET = {'list_per_page': '1'} + folder_qs = Folder.objects.filter(id=self.folder.id) + file_qs = File.objects.filter(folder=self.folder) + items = list(folder_qs) + list(file_qs) + paginator_count = int(request.GET.get('list_per_page', 10)) + paginator = Paginator(items, paginator_count) + + self.assertEqual(paginator.per_page, 1) From 67151ed54200ca0d3760a92b4e3146c888370092 Mon Sep 17 00:00:00 2001 From: Vipul Narang Date: Wed, 18 Sep 2024 16:38:30 +0530 Subject: [PATCH 5/8] fix linting --- tests/test_admin.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_admin.py b/tests/test_admin.py index 8a5869d..e216a23 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -1,5 +1,3 @@ -from cms.test_utils.testcases import CMSTestCase - from django.shortcuts import reverse from django.test import TestCase, RequestFactory from django.contrib.auth.models import User @@ -8,7 +6,6 @@ from djangocms_versioning.helpers import proxy_model from filer.models import File, Folder -from filer.admin.folderadmin import FolderAdmin from tests.base import BaseFilerVersioningTestCase From 10ab1a0cfe817f61a360246503891da0ec7de616 Mon Sep 17 00:00:00 2001 From: Vipul Narang Date: Wed, 18 Sep 2024 16:40:13 +0530 Subject: [PATCH 6/8] fix isort --- tests/test_admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_admin.py b/tests/test_admin.py index e216a23..38090f2 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -1,7 +1,7 @@ -from django.shortcuts import reverse -from django.test import TestCase, RequestFactory from django.contrib.auth.models import User from django.core.paginator import Paginator +from django.shortcuts import reverse +from django.test import TestCase, RequestFactory from djangocms_versioning.helpers import proxy_model From e8604766b5ddfdbff69a6d13e33538ab3ba80f02 Mon Sep 17 00:00:00 2001 From: Vipul Narang Date: Wed, 18 Sep 2024 16:41:46 +0530 Subject: [PATCH 7/8] fix isort --- tests/test_admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_admin.py b/tests/test_admin.py index 38090f2..66ad87c 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -1,7 +1,7 @@ from django.contrib.auth.models import User from django.core.paginator import Paginator from django.shortcuts import reverse -from django.test import TestCase, RequestFactory +from django.test import RequestFactory, TestCase from djangocms_versioning.helpers import proxy_model From 65ea718bfe6e44f0deb52148bc71af4946596be1 Mon Sep 17 00:00:00 2001 From: Vipul Narang Date: Wed, 18 Sep 2024 16:44:20 +0530 Subject: [PATCH 8/8] isort fixes --- tests/test_admin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_admin.py b/tests/test_admin.py index 66ad87c..5c5580e 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -4,7 +4,6 @@ from django.test import RequestFactory, TestCase from djangocms_versioning.helpers import proxy_model - from filer.models import File, Folder from tests.base import BaseFilerVersioningTestCase