From 90558a2e808ad39c3f0f2f84bcd8f061e9471a3c Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 16 Feb 2022 16:45:56 -0500 Subject: [PATCH] Fixes #8671: Fix AttributeError when viewing console/power/interface connection lists --- docs/release-notes/version-3.2.md | 1 + netbox/netbox/tables/tables.py | 48 +++++++++++++++---------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/release-notes/version-3.2.md b/docs/release-notes/version-3.2.md index 742b0532d..dbbc65a78 100644 --- a/docs/release-notes/version-3.2.md +++ b/docs/release-notes/version-3.2.md @@ -149,6 +149,7 @@ Where it is desired to limit the range of available VLANs within a group, users * [#8655](https://github.com/netbox-community/netbox/issues/8655) - Fix AttributeError when viewing cabled interfaces * [#8659](https://github.com/netbox-community/netbox/issues/8659) - Fix display of multi-object custom fields after deleting related object * [#8661](https://github.com/netbox-community/netbox/issues/8661) - Fix ValueError exception when trying to connect a cable +* [#8671](https://github.com/netbox-community/netbox/issues/8671) - Fix AttributeError when viewing console/power/interface connection lists ### Other Changes diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py index 20324ca0e..8413c4673 100644 --- a/netbox/netbox/tables/tables.py +++ b/netbox/netbox/tables/tables.py @@ -127,6 +127,30 @@ class BaseTable(tables.Table): self._objects_count = sum(1 for obj in self.data if hasattr(obj, 'pk')) return self._objects_count + def configure(self, request): + """ + Configure the table for a specific request context. This performs pagination and records + the user's preferred ordering logic. + """ + # Save ordering preference + if request.user.is_authenticated: + table_name = self.__class__.__name__ + if self.prefixed_order_by_field in request.GET: + # If an ordering has been specified as a query parameter, save it as the + # user's preferred ordering for this table. + ordering = request.GET.getlist(self.prefixed_order_by_field) + request.user.config.set(f'tables.{table_name}.ordering', ordering, commit=True) + elif ordering := request.user.config.get(f'tables.{table_name}.ordering'): + # If no ordering has been specified, set the preferred ordering (if any). + self.order_by = ordering + + # Paginate the table results + paginate = { + 'paginator_class': EnhancedPaginator, + 'per_page': get_paginate_count(request) + } + tables.RequestConfig(request, paginate).configure(self) + class NetBoxTable(BaseTable): """ @@ -167,27 +191,3 @@ class NetBoxTable(BaseTable): ]) super().__init__(*args, extra_columns=extra_columns, **kwargs) - - def configure(self, request): - """ - Configure the table for a specific request context. This performs pagination and records - the user's preferred ordering logic. - """ - # Save ordering preference - if request.user.is_authenticated: - table_name = self.__class__.__name__ - if self.prefixed_order_by_field in request.GET: - # If an ordering has been specified as a query parameter, save it as the - # user's preferred ordering for this table. - ordering = request.GET.getlist(self.prefixed_order_by_field) - request.user.config.set(f'tables.{table_name}.ordering', ordering, commit=True) - elif ordering := request.user.config.get(f'tables.{table_name}.ordering'): - # If no ordering has been specified, set the preferred ordering (if any). - self.order_by = ordering - - # Paginate the table results - paginate = { - 'paginator_class': EnhancedPaginator, - 'per_page': get_paginate_count(request) - } - tables.RequestConfig(request, paginate).configure(self)