-
Notifications
You must be signed in to change notification settings - Fork 252
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
Changed the behaviour of Prefix table: allow sorting #5452
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0b18859
Changed the behavior of Prefix table
25a081e
Merge branch 'next' into u/timizuoebideri-4811-prefix-ui-sorting
HanlinMiao d126bb7
Merge branch 'next' into u/timizuoebideri-4811-prefix-ui-sorting
HanlinMiao 85d30bc
Merge branch 'next' into u/timizuoebideri-4811-prefix-ui-sorting
timizuoebideri1 6435129
fix mysql unittest
87a05c6
Update nautobot/ipam/tests/test_tables.py
HanlinMiao 726c2f0
update changelogs
112426f
Merge branch 'u/timizuoebideri-4811-prefix-ui-sorting' of https://git…
81fee32
Merge branch 'next' into u/timizuoebideri-4811-prefix-ui-sorting
timizuoebideri1 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Changed the behavior of Prefix table: now they are sortable, and after sorting is applied, all hierarchy indentations are removed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.test import TestCase | ||
|
||
from nautobot.core.models.querysets import count_related | ||
from nautobot.dcim.models.locations import Location | ||
from nautobot.ipam.models import Prefix | ||
from nautobot.ipam.tables import PrefixTable | ||
|
||
|
||
class PrefixTableTestCase(TestCase): | ||
def _validate_sorted_queryset_same_with_table_queryset(self, queryset, table_class, field_name): | ||
with self.subTest(f"Assert sorting {table_class.__name__} on '{field_name}'"): | ||
table = table_class(queryset, order_by=field_name) | ||
table_queryset_data = table.data.data.values_list("pk", flat=True) | ||
sorted_queryset = queryset.order_by(field_name).values_list("pk", flat=True) | ||
self.assertEqual(list(table_queryset_data), list(sorted_queryset)) | ||
glennmatthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_prefix_table_sort(self): | ||
"""Assert TreeNode model table are orderable.""" | ||
# Due to MySQL's lack of support for combining 'LIMIT' and 'ORDER BY' in a single query, | ||
# hence this approach. | ||
pk_list = Prefix.objects.all().values_list("pk", flat=True)[:20] | ||
pk_list = [str(pk) for pk in pk_list] | ||
queryset = Prefix.objects.filter(pk__in=pk_list) | ||
|
||
# Assets model names | ||
HanlinMiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
table_avail_fields = ["tenant", "vlan", "namespace"] | ||
for table_field_name in table_avail_fields: | ||
self._validate_sorted_queryset_same_with_table_queryset(queryset, PrefixTable, table_field_name) | ||
self._validate_sorted_queryset_same_with_table_queryset(queryset, PrefixTable, f"-{table_field_name}") | ||
|
||
# Assert `prefix` | ||
table_queryset_data = PrefixTable(queryset, order_by="prefix").data.data.values_list("pk", flat=True) | ||
prefix_queryset = queryset.order_by("network", "prefix_length").values_list("pk", flat=True) | ||
self.assertEqual(list(table_queryset_data), list(prefix_queryset)) | ||
table_queryset_data = PrefixTable(queryset, order_by="-prefix").data.data.values_list("pk", flat=True) | ||
prefix_queryset = queryset.order_by("-network", "-prefix_length").values_list("pk", flat=True) | ||
self.assertEqual(list(table_queryset_data), list(prefix_queryset)) | ||
|
||
# Assets `location_count` | ||
location_count_queryset = queryset.annotate(location_count=count_related(Location, "prefixes")).all() | ||
self._validate_sorted_queryset_same_with_table_queryset(location_count_queryset, PrefixTable, "location_count") | ||
self._validate_sorted_queryset_same_with_table_queryset(location_count_queryset, PrefixTable, "-location_count") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this removed because it was unused? My only hesitation is whether we might have any apps that are relying on it that we don't know about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not exposed to the apps/plugin, or do plugin developers use constants not exposed to apps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They aren't supposed to but that doesn't mean they can't. Just being overly cautious here.