Skip to content

Commit

Permalink
Merge pull request #111 from vipulnarang95/feature/add-list-per-page-…
Browse files Browse the repository at this point in the history
…in-folder-admin-to-show-more-items

List per page added to request param infolderadmin
  • Loading branch information
FinalAngel authored Sep 19, 2024
2 parents 153cda5 + 65ea718 commit 8ccedbd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
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)

0 comments on commit 8ccedbd

Please sign in to comment.