mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Management command improvements
This commit is contained in:
parent
f14f6b34ee
commit
f4edfc0592
2 changed files with 16 additions and 10 deletions
|
|
@ -4,16 +4,22 @@ from auditlog.models import LogEntry
|
|||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Deletes all log entries from the database.'
|
||||
help = "Deletes all log entries from the database."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('-y, --yes', action='store_true', default=None,
|
||||
help="Continue without asking confirmation.", dest='yes')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
answer = None
|
||||
answer = options['yes']
|
||||
|
||||
while answer not in ['', 'y', 'n']:
|
||||
answer = input("Are you sure? [y/N]: ").lower().strip()
|
||||
|
||||
if answer == 'y':
|
||||
count = LogEntry.objects.all().count()
|
||||
LogEntry.objects.all().delete()
|
||||
while answer is None:
|
||||
print("This action will clear all log entries from the database.")
|
||||
response = input("Are you sure you want to continue? [y/N]: ").lower().strip()
|
||||
answer = True if response == 'y' else False if response == 'n' else None
|
||||
|
||||
if answer:
|
||||
count, _ = LogEntry.objects.all().delete()
|
||||
print("Deleted %d objects." % count)
|
||||
else:
|
||||
print("Aborted.")
|
||||
|
|
|
|||
|
|
@ -191,8 +191,8 @@ Management commands
|
|||
|
||||
Auditlog provides the ``auditlogflush`` management command to clear all log entries from the database.
|
||||
|
||||
The command asks for confirmation, it is not possible to execute the command without giving any form of (simulated) user
|
||||
input.
|
||||
By default, the command asks for confirmation. It is possible to run the command with the `-y` or `--yes` flag to skip
|
||||
confirmation and immediately delete all entries.
|
||||
|
||||
.. warning::
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue