@@ -168,48 +168,48 @@ def filter_order_ids(self, ids):
168
168
"""
169
169
return _filter_order (self .__class__ .objects , "pk" , ids )
170
170
171
- def ancestor_ids (self ):
171
+ def ancestors_ids (self ):
172
172
with connection .cursor () as cursor :
173
173
cursor .execute (
174
174
ANCESTOR_QUERY .format (relationship_table = edge_model_table ),
175
175
{"id" : self .id },
176
176
)
177
177
return [row [0 ] for row in cursor .fetchall ()]
178
178
179
- def ancestor_and_self_ids (self ):
180
- return self .ancestor_ids () + [self .id ]
179
+ def ancestors_and_self_ids (self ):
180
+ return self .ancestors_ids () + [self .id ]
181
181
182
- def self_and_ancestor_ids (self ):
183
- return self .ancestor_and_self_ids ()[::- 1 ]
182
+ def self_and_ancestors_ids (self ):
183
+ return self .ancestors_and_self_ids ()[::- 1 ]
184
184
185
185
def ancestors (self ):
186
- return self .filter_order_ids (self .ancestor_ids ())
186
+ return self .filter_order_ids (self .ancestors_ids ())
187
187
188
188
def ancestors_and_self (self ):
189
- return self .filter_order_ids (self .ancestor_and_self_ids ())
189
+ return self .filter_order_ids (self .ancestors_and_self_ids ())
190
190
191
191
def self_and_ancestors (self ):
192
192
return self .ancestors_and_self ()[::- 1 ]
193
193
194
- def descendant_ids (self ):
194
+ def descendants_ids (self ):
195
195
with connection .cursor () as cursor :
196
196
cursor .execute (
197
197
DESCENDANT_QUERY .format (relationship_table = edge_model_table ),
198
198
{"id" : self .id },
199
199
)
200
200
return [row [0 ] for row in cursor .fetchall ()]
201
201
202
- def self_and_descendant_ids (self ):
203
- return [self .id ] + self .descendant_ids ()
202
+ def self_and_descendants_ids (self ):
203
+ return [self .id ] + self .descendants_ids ()
204
204
205
205
def descendants_and_self_ids (self ):
206
- return self .self_and_descendant_ids ()[::- 1 ]
206
+ return self .self_and_descendants_ids ()[::- 1 ]
207
207
208
208
def descendants (self ):
209
- return self .filter_order_ids (self .descendant_ids ())
209
+ return self .filter_order_ids (self .descendants_ids ())
210
210
211
211
def self_and_descendants (self ):
212
- return self .filter_order_ids (self .self_and_descendant_ids ())
212
+ return self .filter_order_ids (self .self_and_descendants_ids ())
213
213
214
214
def descendants_and_self (self ):
215
215
return self .self_and_descendants ()[::- 1 ]
@@ -218,15 +218,15 @@ def clan_ids(self):
218
218
"""
219
219
Returns a list of ids with all ancestors, self, and all descendants
220
220
"""
221
- return self .ancestor_ids () + self .self_and_descendant_ids ()
221
+ return self .ancestors_ids () + self .self_and_descendants_ids ()
222
222
223
223
def clan (self ):
224
224
"""
225
225
Returns a queryset with all ancestors, self, and all descendants
226
226
"""
227
227
return self .filter_order_ids (self .clan_ids ())
228
228
229
- def descendant_edges_set (self , cached_results = None ):
229
+ def descendants_edges_set (self , cached_results = None ):
230
230
"""
231
231
Returns a set of descendants edges
232
232
# ToDo: Modify to use CTE
@@ -239,11 +239,11 @@ def descendant_edges_set(self, cached_results=None):
239
239
res = set ()
240
240
for f in self .children .all ():
241
241
res .add (edge_model .objects .get (parent = self .id , child = f .id ))
242
- res .update (f .descendant_edges_set (cached_results = cached_results ))
242
+ res .update (f .descendants_edges_set (cached_results = cached_results ))
243
243
cached_results [self .id ] = res
244
244
return res
245
245
246
- def ancestor_edges_set (self , cached_results = None ):
246
+ def ancestors_edges_set (self , cached_results = None ):
247
247
"""
248
248
Returns a set of ancestors edges
249
249
# ToDo: Modify to use CTE
@@ -256,7 +256,7 @@ def ancestor_edges_set(self, cached_results=None):
256
256
res = set ()
257
257
for f in self .parents .all ():
258
258
res .add (edge_model .objects .get (child = self .id , parent = f .id ))
259
- res .update (f .ancestor_edges_set (cached_results = cached_results ))
259
+ res .update (f .ancestors_edges_set (cached_results = cached_results ))
260
260
cached_results [self .id ] = res
261
261
return res
262
262
@@ -265,8 +265,8 @@ def clan_edges_set(self):
265
265
Returns a set of all edges associated with a given node
266
266
"""
267
267
edges = set ()
268
- edges .update (self .descendant_edges_set ())
269
- edges .update (self .ancestor_edges_set ())
268
+ edges .update (self .descendants_edges_set ())
269
+ edges .update (self .ancestors_edges_set ())
270
270
return edges
271
271
272
272
def path_ids_list (
@@ -411,7 +411,7 @@ def get_leaves(self):
411
411
412
412
@staticmethod
413
413
def circular_checker (parent , child ):
414
- if child .id in parent .self_and_ancestor_ids ():
414
+ if child .id in parent .self_and_ancestors_ids ():
415
415
raise ValidationError ("The object is an ancestor." )
416
416
417
417
return Node
@@ -423,15 +423,15 @@ def descendants(self, node):
423
423
Returns a queryset of all edges descended from the given node
424
424
"""
425
425
return _filter_order (
426
- self .model .objects , "parent_id" , node .self_and_descendant_ids ()
426
+ self .model .objects , "parent_id" , node .self_and_descendants_ids ()
427
427
)
428
428
429
429
def ancestors (self , node ):
430
430
"""
431
431
Returns a queryset of all edges which are ancestors of the given node
432
432
"""
433
433
return _filter_order (
434
- self .model .objects , "child_id" , node .self_and_ancestor_ids ()
434
+ self .model .objects , "child_id" , node .self_and_ancestors_ids ()
435
435
)
436
436
437
437
def clan (self , node ):
0 commit comments