🐛 Solve sorted issues under Python 3.x

sorted does no longer support sorting None values under Python 3. This
patch introduces a utility function that ensures that None values are
replaced by a configurable default value ("" by default) and utilizes
it in places where sorted gets called with a custom sorting key that
can potentially consist of None values.

Closes #3300
This commit is contained in:
Gina Häußge committed 2019-10-10 14:54:07 +02:00
1 parent 09a4fb2515
commit a889bec4d8
8 files changed
+26 -12

No files matched your search

+2 -2
View File
@@ -12,7 +12,7 @@ from octoprint import init_settings
from octoprint.cli import get_ctx_obj_option
from octoprint.access.groups import FilebasedGroupManager
from octoprint.access.users import FilebasedUserManager, UnknownUser, UserAlreadyExists
from octoprint.util import get_class
from octoprint.util import get_class, sv
click.disable_unicode_literals_warning = True
@@ -170,7 +170,7 @@ def deactivate_command(ctx, username):
def _print_list(users):
click.echo("{} users registered in the system:".format(len(users)))
for user in sorted(map(lambda x: x.as_dict(), users), key=lambda x: x.get("name")):
for user in sorted(map(lambda x: x.as_dict(), users), key=lambda x: sv(x.get("name"))):
click.echo("\t{}".format(_user_to_line(user)))