Skip to content

Commit

Permalink
returns deleted_count from graph.delete_instances(), renames var, re #…
Browse files Browse the repository at this point in the history
  • Loading branch information
whatisgalen committed Apr 17, 2024
1 parent 69845af commit c8b2fcf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions arches/app/models/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,15 @@ def delete_instances(self, verbose=False):
"""
if verbose is True:
bar = pyprind.ProgBar(Resource.objects.filter(graph_id=self.graphid).count())
delete_count = 0
for resource in Resource.objects.filter(graph_id=self.graphid):
resource.delete()
delete_count += 1
if verbose is True:
bar.update()
if verbose is True:
print(bar)
return delete_count

def get_tree(self, root=None):
"""
Expand Down
5 changes: 2 additions & 3 deletions arches/app/views/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,11 @@ def delete(self, request, graphid):
elif self.action == "delete_instances":
try:
graph = Graph.objects.get(graphid=graphid)
resource_count = models.ResourceInstance.objects.filter(graph_id=graphid).count()
graph.delete_instances()
deleted_resource_count = graph.delete_instances()
return JSONResponse(
{
"success": True,
"message": f"All {resource_count} resources associated with the Model '{graph.name}' have been successfully deleted.",
"message": f"All {deleted_resource_count} resources associated with the Model '{graph.name}' have been successfully deleted.",
"title": "Resources Successfully Deleted.",
}
)
Expand Down

0 comments on commit c8b2fcf

Please sign in to comment.