My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 59 attachment: 0001-Do-not-close-more-levels-than-have-been-opened-befor.patch (1.5 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
From 891f8e3e6a52a5d680b069509787705890627402 Mon Sep 17 00:00:00 2001
From: Matthias Kestenholz <mk@spinlock.ch>
Date: Wed, 26 Aug 2009 21:04:39 +0200
Subject: [PATCH] Do not close more levels than have been opened before

---
mptt/utils.py | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/mptt/utils.py b/mptt/utils.py
index 2a5dc8f..159b366 100644
--- a/mptt/utils.py
+++ b/mptt/utils.py
@@ -61,6 +61,7 @@ def tree_item_iterator(items, ancestors=False):
"""
structure = {}
opts = None
+ first_item_level = 0
for previous, current, next in previous_current_next(items):
if opts is None:
opts = current._meta
@@ -86,13 +87,14 @@ def tree_item_iterator(items, ancestors=False):
# Set up the ancestors list on the first item
structure['ancestors'] = []

+ first_item_level = current_level
if next:
structure['closed_levels'] = range(current_level,
getattr(next,
opts.level_attr), -1)
else:
# All remaining levels need to be closed
- structure['closed_levels'] = range(current_level, -1, -1)
+ structure['closed_levels'] = range(current_level, first_item_level-1, -1)

# Return a deep copy of the structure dict so this function can
# be used in situations where the iterator is consumed
--
1.5.6.5

Powered by Google Project Hosting