2017-10-05 00:55:43 +02:00
|
|
|
from argparse import ArgumentParser
|
2017-11-16 00:55:49 +01:00
|
|
|
from typing import Any
|
2017-10-05 00:55:43 +02:00
|
|
|
|
2019-05-03 23:20:39 +02:00
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
2017-10-05 00:55:43 +02:00
|
|
|
|
2017-11-16 00:55:49 +01:00
|
|
|
from analytics.lib.counts import COUNT_STATS, do_drop_single_stat
|
2017-10-05 00:55:43 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-10-05 00:55:43 +02:00
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Clear analytics tables."""
|
|
|
|
|
2017-11-05 06:54:00 +01:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2017-10-05 00:55:43 +02:00
|
|
|
parser.add_argument('--force',
|
|
|
|
action='store_true',
|
|
|
|
help="Actually do it.")
|
|
|
|
parser.add_argument('--property',
|
|
|
|
type=str,
|
|
|
|
help="The property of the stat to be cleared.")
|
|
|
|
|
2017-11-05 06:54:00 +01:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2017-10-05 00:55:43 +02:00
|
|
|
property = options['property']
|
|
|
|
if property not in COUNT_STATS:
|
2020-06-10 06:41:04 +02:00
|
|
|
raise CommandError(f"Invalid property: {property}")
|
2017-10-05 00:55:43 +02:00
|
|
|
if not options['force']:
|
2019-05-03 23:20:39 +02:00
|
|
|
raise CommandError("No action taken. Use --force.")
|
2017-10-05 00:55:43 +02:00
|
|
|
|
|
|
|
do_drop_single_stat(property)
|