2017-01-26 19:19:23 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
2016-07-27 16:17:59 +00:00
|
|
|
|
|
|
|
|
from auditlog.models import LogEntry
|
|
|
|
|
|
|
|
|
|
|
2017-01-26 19:19:23 +00:00
|
|
|
class Command(BaseCommand):
|
2020-08-31 12:22:50 +00:00
|
|
|
help = "Deletes all log entries from the database."
|
2016-07-27 16:17:59 +00:00
|
|
|
|
2020-08-31 12:22:50 +00:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
|
parser.add_argument('-y, --yes', action='store_true', default=None,
|
|
|
|
|
help="Continue without asking confirmation.", dest='yes')
|
2016-07-27 16:17:59 +00:00
|
|
|
|
2020-08-31 12:22:50 +00:00
|
|
|
def handle(self, *args, **options):
|
|
|
|
|
answer = options['yes']
|
2016-07-27 16:17:59 +00:00
|
|
|
|
2020-09-07 07:10:37 +00:00
|
|
|
if answer is None:
|
|
|
|
|
self.stdout.write("This action will clear all log entries from the database.")
|
2020-08-31 12:22:50 +00:00
|
|
|
response = input("Are you sure you want to continue? [y/N]: ").lower().strip()
|
2020-09-07 07:10:37 +00:00
|
|
|
answer = response == 'y'
|
2016-07-27 16:17:59 +00:00
|
|
|
|
2020-08-31 12:22:50 +00:00
|
|
|
if answer:
|
|
|
|
|
count, _ = LogEntry.objects.all().delete()
|
2020-09-07 07:10:37 +00:00
|
|
|
self.stdout.write("Deleted %d objects." % count)
|
2020-08-31 12:22:50 +00:00
|
|
|
else:
|
2020-09-07 07:10:37 +00:00
|
|
|
self.stdout.write("Aborted.")
|