From 0a864c7f87030e616d14e551f58c73e70d17eb49 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 25 May 2020 01:46:52 +0100 Subject: [PATCH] 2to3 sort comparison key change --- core/views_caves.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/core/views_caves.py b/core/views_caves.py index 1a7d077..b409831 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -37,19 +37,11 @@ def padnumber(x): def numericalcmp(x, y): return cmp(padnumber(x), padnumber(y)) - - -def caveCmp(x, y): - if x.kataster_number: - if y.kataster_number: - return numericalcmp(x.kataster_number, y.kataster_number) # Note that cave kataster numbers are not generally integers. - else: - return -1 - else: - if y.kataster_number: - return 1 - else: - return numericalcmp(x.unofficial_number, y.unofficial_number) +def caveKey(x): + """python3 function for sort. + Note that cave kataster numbers are not generally integers + """ + return x.kataster_number def caveindex(request): caves = Cave.objects.all() @@ -57,8 +49,9 @@ def caveindex(request): notablecaves = [Cave.objects.get(kataster_number=kataster_number) for kataster_number in notablecavehrefs ] caves1623 = list(Cave.objects.filter(area__short_name = "1623")) caves1626 = list(Cave.objects.filter(area__short_name = "1626")) - caves1623.sort(caveCmp) - caves1626.sort(caveCmp) + #python2 to python3 issue https://realpython.com/python-sort/ + caves1623.sort(key=caveKey) + caves1626.sort(key=caveKey) return render(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':notablecaves, 'cavepage': True}) def millenialcaves(request):