Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List per page added to request param infolderadmin #111

Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion djangocms_versioning_filer/monkeypatch/admin/folderadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ def directory_listing(self, request, folder_id=None, viewtype=None):
permissions = {}

items = folder_children + folder_files
paginator = Paginator(items, filer.settings.FILER_PAGINATE_BY)
# 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)

# Are we moving to clipboard?
if request.method == 'POST' and '_save' not in request.POST:
Expand Down
28 changes: 27 additions & 1 deletion tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.contrib.auth.models import User
from django.core.paginator import Paginator
from django.shortcuts import reverse
from django.test import RequestFactory, TestCase

from djangocms_versioning.helpers import proxy_model
from filer.models import File
from filer.models import File, Folder

from tests.base import BaseFilerVersioningTestCase

Expand Down Expand Up @@ -55,3 +58,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)
Loading