From ce6cd9c43ab05938732233d932c11bbae8daa636 Mon Sep 17 00:00:00 2001 From: Jesse van den Kieboom Date: Thu, 14 Aug 2014 20:16:51 +0200 Subject: [PATCH] Sort category children, except for categories --- cldoc/nodes/category.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cldoc/nodes/category.py b/cldoc/nodes/category.py index 5749aa6..e3445f5 100644 --- a/cldoc/nodes/category.py +++ b/cldoc/nodes/category.py @@ -27,6 +27,19 @@ def is_unlabeled(self): return True def sorted_children(self): - return list(self.children) + schildren = list(Node.sorted_children(self)) + + # Keep categories in order though + c = [x for x in self.children if isinstance(x, Category)] + c.reverse() + + if len(c) == 0: + return schildren + + for i in range(0, len(schildren)): + if isinstance(schildren[i], Category): + schildren[i] = c.pop() + + return schildren # vi:ts=4:et