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 20 attachment: qs-rf.diff (7.1 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
Index: /Users/go/working_copies/django-mptt/mptt/managers.py
===================================================================
--- /Users/go/working_copies/django-mptt/mptt/managers.py (revision 104)
+++ /Users/go/working_copies/django-mptt/mptt/managers.py (working copy)
@@ -5,6 +5,7 @@
from django.utils.translation import ugettext as _

from mptt.exceptions import InvalidMove
+from mptt.utils import get_actual_opts

__all__ = ('TreeManager',)

@@ -33,6 +34,8 @@
"""
A manager for working with trees of objects.
"""
+
+
def __init__(self, parent_attr, left_attr, right_attr, tree_id_attr,
level_attr):
"""
@@ -73,7 +76,8 @@
If ``True``, the count will be for each item and all of its
descendants, otherwise it will be for each item itself.
"""
- opts = self.model._meta
+ #opts = self.model._meta
+ opts = get_actual_opts(self.model)
if cumulative:
subquery = CUMULATIVE_COUNT_SUBQUERY % {
'rel_table': qn(rel_model._meta.db_table),
@@ -161,7 +165,7 @@
if commit:
node.save()
return node
-
+
def move_node(self, node, target, position='last-child'):
"""
Moves ``node`` relative to a given ``target`` node as specified
@@ -258,7 +262,8 @@
Creates space for a new tree by incrementing all tree ids
greater than ``target_tree_id``.
"""
- opts = self.model._meta
+ #opts = self.model._meta
+ opts = get_actual_opts(self.model)
cursor = connection.cursor()
cursor.execute("""
UPDATE %(table)s
@@ -273,7 +278,8 @@
Determines the next largest unused tree id for the tree managed
by this manager.
"""
- opts = self.model._meta
+ #opts = self.model._meta
+ opts = get_actual_opts(self.model)
cursor = connection.cursor()
cursor.execute('SELECT MAX(%s) FROM %s' % (
qn(opts.get_field(self.tree_id_attr).column),
@@ -293,7 +299,8 @@
have its parent field set to ``NULL``. Otherwise, ``node`` will
have ``parent_pk`` set for its parent field.
"""
- opts = self.model._meta
+ #opts = self.model._meta
+ opts = get_actual_opts(self.model)
inter_tree_move_query = """
UPDATE %(table)s
SET %(level)s = CASE
@@ -396,7 +403,9 @@
if node == target:
raise InvalidMove(_('A node may not be made a sibling of itself.'))

- opts = self.model._meta
+ #opts = self.model._meta
+ opts = get_actual_opts(self.model)
+
tree_id = getattr(node, self.tree_id_attr)
target_tree_id = getattr(target, self.tree_id_attr)

@@ -467,7 +476,9 @@
the values of the left and right columns by ``size`` after the
given ``target`` point.
"""
- opts = self.model._meta
+ #opts = self.model._meta
+ opts = get_actual_opts(self.model)
+
space_query = """
UPDATE %(table)s
SET %(left)s = CASE
@@ -610,7 +621,8 @@
if left_right_change > 0:
gap_size = -gap_size

- opts = self.model._meta
+ #opts = self.model._meta
+ opts = get_actual_opts(self.model)
# The level update must come before the left update to keep
# MySQL happy - left seems to refer to the updated value
# immediately after its update has been specified in the query
@@ -692,7 +704,8 @@
self._create_space(width, space_target, new_tree_id)

# Move the root node, making it a child node
- opts = self.model._meta
+ #opts = self.model._meta
+ opts = get_actual_opts(self.model)
move_tree_query = """
UPDATE %(table)s
SET %(level)s = %(level)s - %%s,
Index: /Users/go/working_copies/django-mptt/mptt/__init__.py
===================================================================
--- /Users/go/working_copies/django-mptt/mptt/__init__.py (revision 104)
+++ /Users/go/working_copies/django-mptt/mptt/__init__.py (working copy)
@@ -8,9 +8,15 @@
"""
pass

+class ParentNotRegisted(Exception):
+ """
+ An attempt was made to register a model for MPTT, but parent was not registered.
+ """
+ pass
+
registry = []

-def register(model, parent_attr='parent', left_attr='lft', right_attr='rght',
+def register(model, parent_model=None, parent_attr='parent', left_attr='lft', right_attr='rght',
tree_id_attr='tree_id', level_attr='level',
tree_manager_attr='tree', order_insertion_by=None):
"""
@@ -24,11 +30,22 @@
from mptt import models
from mptt.signals import pre_delete, pre_save
from mptt.managers import TreeManager
+
+ if parent_model:
+ if parent_model not in registry:
+ raise ParentNotRegistered(_('You must register parent model %s before register model %s.') % (parent_model.__name__, model.__name__))

if model in registry:
raise AlreadyRegistered(_('The model %s has already been registered.') % model.__name__)
registry.append(model)

+ if parent_model:
+ opts = model._meta
+ opts.mptt_parent_meta = parent_model._meta
+ dispatcher.connect(pre_save, signal=model_signals.pre_save, sender=model)
+ dispatcher.connect(pre_delete, signal=model_signals.pre_delete, sender=model)
+ return
+
# Add tree options to the model's Options
opts = model._meta
opts.parent_attr = parent_attr
Index: /Users/go/working_copies/django-mptt/mptt/signals.py
===================================================================
--- /Users/go/working_copies/django-mptt/mptt/signals.py (revision 104)
+++ /Users/go/working_copies/django-mptt/mptt/signals.py (working copy)
@@ -7,6 +7,8 @@
from django.db.models.query import Q
from django.utils.translation import ugettext as _

+from mptt.utils import get_actual_opts
+
__all__ = ('pre_save', 'pre_delete')

def _insertion_target_filters(node, order_insertion_by):
@@ -96,8 +98,9 @@
"""
if kwargs.get('raw'):
return
-
- opts = instance._meta
+
+ #opts = instance._meta
+ opts = get_actual_opts(instance)
parent = getattr(instance, opts.parent_attr)
if not instance.pk:
if (getattr(instance, opts.left_attr) and
Index: /Users/go/working_copies/django-mptt/mptt/utils.py
===================================================================
--- /Users/go/working_copies/django-mptt/mptt/utils.py (revision 104)
+++ /Users/go/working_copies/django-mptt/mptt/utils.py (working copy)
@@ -4,10 +4,17 @@
"""
import copy
import itertools
+from artshow import mptt

__all__ = ('previous_current_next', 'tree_item_iterator',
- 'drilldown_tree_for_node')
+ 'drilldown_tree_for_node', 'get_actual_opts')

+def get_actual_opts(model):
+ if hasattr(model._meta, 'mptt_parent_meta'):
+ return model._meta.mptt_parent_meta
+ else:
+ return model._meta
+
def previous_current_next(items):
"""
From http://www.wordaligned.org/articles/zippy-triples-served-with-python
Powered by Google Project Hosting