2020-10-25 23:03:02 +01:00
|
|
|
from django.core.management import BaseCommand
|
2020-12-22 13:04:22 +01:00
|
|
|
from django.db import transaction
|
2020-10-25 23:03:02 +01:00
|
|
|
|
|
|
|
|
from documents.mixins import Renderable
|
2020-11-09 20:29:02 +01:00
|
|
|
from documents.tasks import index_reindex, index_optimize
|
2020-10-25 23:03:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Command(Renderable, BaseCommand):
|
|
|
|
|
|
2020-10-27 17:08:18 +01:00
|
|
|
help = "Manages the document index."
|
2020-10-25 23:03:02 +01:00
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
self.verbosity = 0
|
|
|
|
|
BaseCommand.__init__(self, *args, **kwargs)
|
|
|
|
|
|
2020-10-27 17:08:18 +01:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
|
parser.add_argument("command", choices=['reindex', 'optimize'])
|
|
|
|
|
|
2020-10-25 23:03:02 +01:00
|
|
|
def handle(self, *args, **options):
|
|
|
|
|
|
|
|
|
|
self.verbosity = options["verbosity"]
|
2020-12-22 13:04:22 +01:00
|
|
|
with transaction.atomic():
|
|
|
|
|
if options['command'] == 'reindex':
|
|
|
|
|
index_reindex()
|
|
|
|
|
elif options['command'] == 'optimize':
|
|
|
|
|
index_optimize()
|