Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/serveradmin/serveradmin/servershell/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ def edit(request):
return _edit(request, server, True)


def _sort_multi_values(values) -> list:
"""Sort multi attribute values for display

Multi attribute values are sets and have no stable order. Sort them
by their natural order and fall back to the string representation for
values that can not be compared with each other, e.g. inet attributes
without an address family restriction holding IPv4 and IPv6 values.
"""
try:
return sorted(values)
except TypeError:
return sorted(values, key=str)


def _edit(request: HttpRequest, server, edit_mode=False, template='edit'): # NOQA: C901
# @TODO work with ServerAttribute models here and use Django forms
invalid_attrs = set()
Expand Down Expand Up @@ -360,6 +374,9 @@ def _edit(request: HttpRequest, server, edit_mode=False, template='edit'): # NO
):
is_related_attribute = True

if attribute.multi and value is not None:
value = _sort_multi_values(value)

fields_set.add(key)
fields.append({
'key': key,
Expand Down
Loading