diff --git a/src/django_bootstrap5/templatetags/django_bootstrap5.py b/src/django_bootstrap5/templatetags/django_bootstrap5.py index 4d6ddffd..59074f5b 100644 --- a/src/django_bootstrap5/templatetags/django_bootstrap5.py +++ b/src/django_bootstrap5/templatetags/django_bootstrap5.py @@ -698,6 +698,11 @@ def bootstrap_pagination(page, **kwargs): :default: ``None`` + extra_classes + Appends string as extra CSS classes to the pagination ul. + + :default: ``None`` + extra Any extra page parameters. @@ -733,6 +738,7 @@ def get_pagination_context( url=None, size=None, justify_content=None, + extra_classes=None, extra=None, parameter_name="page", ): @@ -800,6 +806,9 @@ def get_pagination_context( " Valid values are 'start', 'center', 'end'." ) + if extra_classes: + pagination_css_classes.append(extra_classes) + return { "bootstrap_pagination_url": url, "num_pages": num_pages, diff --git a/tests/test_bootstrap_pagination.py b/tests/test_bootstrap_pagination.py index 9489b0b0..191635de 100644 --- a/tests/test_bootstrap_pagination.py +++ b/tests/test_bootstrap_pagination.py @@ -106,6 +106,131 @@ def test_paginator_illegal(self): with self.assertRaises(ValueError): self.render("{{% bootstrap_pagination page pages_to_show=-5 %}", {"page": self.paginator.page(2)}) + def test_paginator_extra_css(self): + """Test only the extra_classes parameter.""" + # Test with single CSS class + self.assertHTMLEqual( + self.render('{% bootstrap_pagination page extra_classes="custom-pagination" %}', {"page": self.paginator.page(2)}), + ( + '" + ), + ) + + # Test with multiple CSS classes + self.assertHTMLEqual( + self.render('{% bootstrap_pagination page extra_classes="my-custom-class another-class" %}', {"page": self.paginator.page(2)}), + ( + '" + ), + ) + + # Test with empty string (should not add anything) + self.assertHTMLEqual( + self.render('{% bootstrap_pagination page extra_classes="" %}', {"page": self.paginator.page(2)}), + ( + '" + ), + ) + + def test_paginator_extra_classes_with_size(self): + """Test extra_classes combined with size parameter.""" + self.assertHTMLEqual( + self.render('{% bootstrap_pagination page size="sm" extra_classes="custom-small" %}', {"page": self.paginator.page(2)}), + ( + '" + ), + ) + + self.assertHTMLEqual( + self.render('{% bootstrap_pagination page size="lg" extra_classes="large-custom" %}', {"page": self.paginator.page(2)}), + ( + '" + ), + ) + + def test_paginator_extra_classes_with_justify(self): + """Test extra_classes combined with justify_content parameter.""" + self.assertHTMLEqual( + self.render('{% bootstrap_pagination page justify_content="center" extra_classes="centered-custom" %}', {"page": self.paginator.page(2)}), + ( + '" + ), + ) + + self.assertHTMLEqual( + self.render('{% bootstrap_pagination page justify_content="end" extra_classes="end-aligned" %}', {"page": self.paginator.page(2)}), + ( + '" + ), + ) + + def test_paginator_extra_classes_with_all_options(self): + """Test extra_classes combined with size and justify_content parameters.""" + self.assertHTMLEqual( + self.render('{% bootstrap_pagination page size="lg" justify_content="center" extra_classes="all-options-test" %}', {"page": self.paginator.page(2)}), + ( + '" + ), + ) + + def test_paginator_extra_classes_with_url_and_extra(self): + """Test extra_classes with URL and extra parameters.""" + html = self.bootstrap_pagination( + self.paginator.page(2), + extra='url="/projects/?foo=bar" extra_classes="url-test-class"' + ) + self.assertHTMLEqual( + html, + ( + '" + ), + ) + class LargePaginatorTestCase(BootstrapTestCase): @classmethod @@ -125,3 +250,14 @@ def test_paginator_ellipsis(self): html = self.render("{{% bootstrap_pagination page %}", {"page": self.paginator.page(49)}) self.assertInHTML('
  • ', html) self.assertInHTML("…", html, count=1) + + def test_paginator_ellipsis_with_extra_css(self): + """Test that pagination_extra_classes works correctly with ellipsis pagination.""" + html = self.render('{% bootstrap_pagination page extra_classes="ellipsis-test" %}', {"page": self.paginator.page(33)}) + + # Check that the extra CSS class is present + self.assertIn('class="pagination ellipsis-test"', html) + + # Check that ellipsis are still rendered correctly + self.assertInHTML('
  • ', html) + self.assertInHTML('
  • ', html)