diff --git a/autocomplete_multi_models/management/commands/makeautocompleteindex.py b/autocomplete_multi_models/management/commands/makeautocompleteindex.py index b10880a9f8b4ac7abf49e15e13dd8c4287a3238e..32bc19c44a592bc34bdd345e8e153bde150f14e7 100644 --- a/autocomplete_multi_models/management/commands/makeautocompleteindex.py +++ b/autocomplete_multi_models/management/commands/makeautocompleteindex.py @@ -8,6 +8,7 @@ from autocomplete_multi_models import business_process, models, utils class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--forced', action='store_true') + parser.add_argument('--no-fill-if-empty', action='store_true') @transaction.atomic def handle(self, *args, **options): @@ -18,8 +19,7 @@ class Command(BaseCommand): business_process.rebuild_index() te = time.time() print(f"Index rebuild in {int((te - ts) * 100) / 100}s, it contains {models.IndexedWord.objects.count()} words") - if not models.IndexedWord.objects.exists(): - print("DB is empty, prefilling it with some words") + if not options['no_fill_if_empty'] and not models.IndexedWord.objects.exists(): for s in [ "Coming soon", "coming soon", diff --git a/autocomplete_multi_models/tests/test_business_process.py b/autocomplete_multi_models/tests/test_business_process.py index c8c6eb9124f1d477b53e68f6fb06dd5cea595016..ef1dbab8fe4eef979f1610cf209f60ffd58ff309 100644 --- a/autocomplete_multi_models/tests/test_business_process.py +++ b/autocomplete_multi_models/tests/test_business_process.py @@ -157,7 +157,7 @@ class NeedRebuildDefaultBehaviorTestCase(test_helpers.ChangeAutoCompleteSettings self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None)) business_process.set_setting_in_storage(utils.REBUILD_NEEDED, True) self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None)) - management.call_command('makeautocompleteindex') + management.call_command('makeautocompleteindex', no_fill_if_empty=True) self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None)) self.assertEqual(models.IndexedWord.objects.count(), 0) @@ -177,7 +177,7 @@ class NeedRebuildFileSettingsBasedTestCase(test_helpers.ChangeAutoCompleteSettin models.IndexedWord.objects.create(word="TOTO") self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, True)) - management.call_command('makeautocompleteindex') + management.call_command('makeautocompleteindex', no_fill_if_empty=True) self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, False)) self.assertEqual(models.IndexedWord.objects.count(), 0) @@ -187,7 +187,7 @@ class NeedRebuildFileSettingsBasedTestCase(test_helpers.ChangeAutoCompleteSettin self.assertEqual(models.IndexedWord.objects.count(), 1) business_process.set_setting_in_storage(utils.REBUILD_NEEDED, False) - management.call_command('makeautocompleteindex', forced=True) + management.call_command('makeautocompleteindex', forced=True, no_fill_if_empty=True) self.assertEqual(models.IndexedWord.objects.count(), 0) signals.instance_delete(sender=None, instance=None, field_names=[]) diff --git a/setup.cfg b/setup.cfg index 2849107027d4f271adb2db5f040dd656b6ae7747..b146079b924c9a311490b074519f8a65b6df101a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = autocomplete-multi-models -version = 0.4.3 +version = 0.4.3.1 description = An app that index fields across multiple models, and expose an api to query for word similar to the query. long_description = file: README.md author = Bryan Brancotte