Skip to content

Commit

Permalink
Merge pull request #10837 from archesproject/9788_add_edit_log_manage…
Browse files Browse the repository at this point in the history
…ment_command

Add clear edit log management command #9788
  • Loading branch information
apeters authored May 1, 2024
2 parents 1a3afb8 + 4be40d4 commit a4975db
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions arches/management/commands/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,22 @@ def add_arguments(self, parser):
help="A graphid of the Resource Model you would like to remove all instances from.",
)

parser.add_argument(
"-e",
"--editlog",
action="store_true",
dest="editlog",
help="used to clear the edit log. If a graphid is provided, only the edit log for that graph will be cleared.",
)

def handle(self, *args, **options):
if options["operation"] == "remove_resources":
self.remove_resources(force=options["yes"], graphid=options["graph"])
self.remove_resources(force=options["yes"], graphid=options["graph"], clear_edit_log=options["editlog"])

if options["operation"] == "clear_edit_log":
self.clear_edit_log(graphid=options["graph"])

def remove_resources(self, load_id="", graphid=None, force=False):
def remove_resources(self, load_id="", graphid=None, force=False, clear_edit_log=False):
"""
Runs the resource_remover command found in data_management.resources
"""
Expand All @@ -66,8 +77,22 @@ def remove_resources(self, load_id="", graphid=None, force=False):

if graphid is None:
resource_remover.clear_resources()
if clear_edit_log:
self.clear_edit_log()
else:
graph = Graph.objects.get(graphid=graphid)
graph.delete_instances(verbose=True)
if clear_edit_log:
self.clear_edit_log(graphid)

return

def clear_edit_log(self, graphid=None):
"""
Clears the edit log
"""
if graphid:
models.EditLog.objects.filter(resourceclassid=graphid).delete()
else:
models.EditLog.objects.all().delete()

0 comments on commit a4975db

Please sign in to comment.