diff --git a/core/views_caves.py b/core/views_caves.py index d8ced23..90b6f5e 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -21,14 +21,26 @@ def getCave(cave_id): cave = Cave.objects.get(unofficial_number=cave_id) return cave +def pad5(x): + return "0" * (5 -len(x.group(0))) + x.group(0) +def padnumber(x): + return re.sub("\d+", pad5, x) +def numericalcmp(x, y): + return cmp(padnumber(x), padnumber(y)) + + + def caveCmp(x, y): if x.kataster_number: if y.kataster_number: - return cmp(x.kataster_number, y.kataster_number) + return numericalcmp(x.kataster_number, y.kataster_number) else: return -1 else: - return 1 + if y.kataster_number: + return 1 + else: + return numericalcmp(x.unofficial_number, y.unofficial_number) def caveindex(request): caves = Cave.objects.all()