Skip to content

Commit 5c431e9

Browse files
Modified to use plurals consistently for "ancestors" & "descendants"
1 parent a733196 commit 5c431e9

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

django_postgresql_dag/models.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -168,48 +168,48 @@ def filter_order_ids(self, ids):
168168
"""
169169
return _filter_order(self.__class__.objects, "pk", ids)
170170

171-
def ancestor_ids(self):
171+
def ancestors_ids(self):
172172
with connection.cursor() as cursor:
173173
cursor.execute(
174174
ANCESTOR_QUERY.format(relationship_table=edge_model_table),
175175
{"id": self.id},
176176
)
177177
return [row[0] for row in cursor.fetchall()]
178178

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]
181181

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]
184184

185185
def ancestors(self):
186-
return self.filter_order_ids(self.ancestor_ids())
186+
return self.filter_order_ids(self.ancestors_ids())
187187

188188
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())
190190

191191
def self_and_ancestors(self):
192192
return self.ancestors_and_self()[::-1]
193193

194-
def descendant_ids(self):
194+
def descendants_ids(self):
195195
with connection.cursor() as cursor:
196196
cursor.execute(
197197
DESCENDANT_QUERY.format(relationship_table=edge_model_table),
198198
{"id": self.id},
199199
)
200200
return [row[0] for row in cursor.fetchall()]
201201

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()
204204

205205
def descendants_and_self_ids(self):
206-
return self.self_and_descendant_ids()[::-1]
206+
return self.self_and_descendants_ids()[::-1]
207207

208208
def descendants(self):
209-
return self.filter_order_ids(self.descendant_ids())
209+
return self.filter_order_ids(self.descendants_ids())
210210

211211
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())
213213

214214
def descendants_and_self(self):
215215
return self.self_and_descendants()[::-1]
@@ -218,15 +218,15 @@ def clan_ids(self):
218218
"""
219219
Returns a list of ids with all ancestors, self, and all descendants
220220
"""
221-
return self.ancestor_ids() + self.self_and_descendant_ids()
221+
return self.ancestors_ids() + self.self_and_descendants_ids()
222222

223223
def clan(self):
224224
"""
225225
Returns a queryset with all ancestors, self, and all descendants
226226
"""
227227
return self.filter_order_ids(self.clan_ids())
228228

229-
def descendant_edges_set(self, cached_results=None):
229+
def descendants_edges_set(self, cached_results=None):
230230
"""
231231
Returns a set of descendants edges
232232
# ToDo: Modify to use CTE
@@ -239,11 +239,11 @@ def descendant_edges_set(self, cached_results=None):
239239
res = set()
240240
for f in self.children.all():
241241
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))
243243
cached_results[self.id] = res
244244
return res
245245

246-
def ancestor_edges_set(self, cached_results=None):
246+
def ancestors_edges_set(self, cached_results=None):
247247
"""
248248
Returns a set of ancestors edges
249249
# ToDo: Modify to use CTE
@@ -256,7 +256,7 @@ def ancestor_edges_set(self, cached_results=None):
256256
res = set()
257257
for f in self.parents.all():
258258
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))
260260
cached_results[self.id] = res
261261
return res
262262

@@ -265,8 +265,8 @@ def clan_edges_set(self):
265265
Returns a set of all edges associated with a given node
266266
"""
267267
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())
270270
return edges
271271

272272
def path_ids_list(
@@ -411,7 +411,7 @@ def get_leaves(self):
411411

412412
@staticmethod
413413
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():
415415
raise ValidationError("The object is an ancestor.")
416416

417417
return Node
@@ -423,15 +423,15 @@ def descendants(self, node):
423423
Returns a queryset of all edges descended from the given node
424424
"""
425425
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()
427427
)
428428

429429
def ancestors(self, node):
430430
"""
431431
Returns a queryset of all edges which are ancestors of the given node
432432
"""
433433
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()
435435
)
436436

437437
def clan(self, node):

0 commit comments

Comments
 (0)