From 2208f0748b8e6b086bac9f6bcc401b62de415b7b Mon Sep 17 00:00:00 2001 From: expo Date: Sun, 5 Aug 2012 19:26:24 +0200 Subject: [PATCH] Fixed cave order --- core/views_caves.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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()