From bf6345aa90afd5ee5c7a59ae6fd1d4ad73509803 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 19 Jan 2022 09:14:38 -0500 Subject: [PATCH] Closes #5429: Enable toggling the placement of table paginators --- docs/development/user-preferences.md | 1 + docs/release-notes/version-3.2.md | 1 + netbox/netbox/preferences.py | 10 ++++++++++ netbox/templates/htmx/table.html | 12 ++++++++++-- netbox/users/forms.py | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/development/user-preferences.md b/docs/development/user-preferences.md index 622fbb4b9..ceb5321a9 100644 --- a/docs/development/user-preferences.md +++ b/docs/development/user-preferences.md @@ -8,6 +8,7 @@ The `users.UserConfig` model holds individual preferences for each user in the f |--------------------------|---------------------------------------------------------------| | data_format | Preferred format when rendering raw data (JSON or YAML) | | pagination.per_page | The number of items to display per page of a paginated table | +| pagination.placement | Where to display the paginator controls relative to the table | | tables.${table}.columns | The ordered list of columns to display when viewing the table | | tables.${table}.ordering | A list of column names by which the table should be ordered | | ui.colormode | Light or dark mode in the user interface | diff --git a/docs/release-notes/version-3.2.md b/docs/release-notes/version-3.2.md index 09701f800..432d6fafc 100644 --- a/docs/release-notes/version-3.2.md +++ b/docs/release-notes/version-3.2.md @@ -60,6 +60,7 @@ Inventory item templates can be arranged hierarchically within a device type, an ### Enhancements +* [#5429](https://github.com/netbox-community/netbox/issues/5429) - Enable toggling the placement of table paginators * [#6954](https://github.com/netbox-community/netbox/issues/6954) - Remember users' table ordering preferences * [#7650](https://github.com/netbox-community/netbox/issues/7650) - Add support for local account password validation * [#7679](https://github.com/netbox-community/netbox/issues/7679) - Add actions menu to all object tables diff --git a/netbox/netbox/preferences.py b/netbox/netbox/preferences.py index 4cad8cf24..aec8bc752 100644 --- a/netbox/netbox/preferences.py +++ b/netbox/netbox/preferences.py @@ -26,6 +26,16 @@ PREFERENCES = { description='The number of objects to display per page', coerce=lambda x: int(x) ), + 'pagination.placement': UserPreference( + label='Paginator placement', + choices=( + ('bottom', 'Bottom'), + ('top', 'Top'), + ('both', 'Both'), + ), + description='Where the paginator controls will be displayed relative to a table', + default='bottom' + ), # Miscellaneous 'data_format': UserPreference( diff --git a/netbox/templates/htmx/table.html b/netbox/templates/htmx/table.html index c5d0ac46b..6f168ac52 100644 --- a/netbox/templates/htmx/table.html +++ b/netbox/templates/htmx/table.html @@ -1,5 +1,13 @@ {# Render an HTMX-enabled table with paginator #} +{% load helpers %} {% load render_table from django_tables2 %} -{% render_table table 'inc/table_htmx.html' %} -{% include 'inc/paginator_htmx.html' with paginator=table.paginator page=table.page %} +{% with preferences|get_key:"pagination.placement" as paginator_placement %} + {% if paginator_placement == 'top' or paginator_placement == 'both' %} + {% include 'inc/paginator_htmx.html' with paginator=table.paginator page=table.page %} + {% endif %} + {% render_table table 'inc/table_htmx.html' %} + {% if paginator_placement != 'top' %} + {% include 'inc/paginator_htmx.html' with paginator=table.paginator page=table.page %} + {% endif %} +{% endwith %} diff --git a/netbox/users/forms.py b/netbox/users/forms.py index 70e300a8c..5a99adc5a 100644 --- a/netbox/users/forms.py +++ b/netbox/users/forms.py @@ -47,6 +47,7 @@ class UserConfigForm(BootstrapMixin, forms.ModelForm, metaclass=UserConfigFormMe fieldsets = ( ('User Interface', ( 'pagination.per_page', + 'pagination.placement', 'ui.colormode', )), ('Miscellaneous', (