Skip to content
Snippets Groups Projects
Commit 7a2ae61e authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Merge branch 'add-count' into 'main'

allows to disable auto indexing, provide a basic in-memory storage for...

See merge request hub/django-autocomplete-multi-models!3
parents a48902ba d74594b8
No related branches found
No related tags found
No related merge requests found
......@@ -15,14 +15,18 @@ _AUTOCOMPLETE_MIN_LENGTH = utils.DEFAULT_AUTOCOMPLETE_MIN_LENGTH
_AUTOCOMPLETE_MIN_SIMILARITY = utils.DEFAULT_AUTOCOMPLETE_MIN_SIMILARITY
_AUTOCOMPLETE_LIMIT = utils.DEFAULT_AUTOCOMPLETE_LIMIT
_CAN_BE_INDEXED_BY_AUTOCOMPLETE_FUNCTION_NAME = utils.DEFAULT_CAN_BE_INDEXED_BY_AUTOCOMPLETE_FUNCTION_NAME
__in_mem_storage = {
utils.AUTO_UPDATE_ENABLED: True,
utils.REBUILD_NEEDED: True,
}
def get_setting_from_storage(key, default):
return key == utils.REBUILD_NEEDED
return __in_mem_storage.get(key, default)
def set_setting_in_storage(key, value):
pass
__in_mem_storage[key] = value
def split_string(value):
......
......@@ -2,7 +2,8 @@ from autocomplete_multi_models import business_process, utils
def instance_update(sender, instance, field_names, **kwargs):
business_process.add_instance_to_index(instance, field_names)
if business_process.get_setting_from_storage(utils.AUTO_UPDATE_ENABLED, True):
business_process.add_instance_to_index(instance, field_names)
def instance_delete(sender, instance, field_names, **kwargs):
......
......@@ -133,11 +133,11 @@ class NeedRebuildDefaultBehaviorTestCase(test_helpers.ChangeAutoCompleteSettings
def test_it(self):
self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, True))
business_process.set_setting_in_storage(utils.REBUILD_NEEDED, False)
self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, True))
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, True))
self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None))
management.call_command('makeautocompleteindex')
self.assertTrue(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, True))
self.assertFalse(business_process.get_setting_from_storage(utils.REBUILD_NEEDED, None))
self.assertEqual(models.IndexedWord.objects.count(), 0)
......
......@@ -7,6 +7,7 @@ DEFAULT_AUTOCOMPLETE_MIN_SIMILARITY = 0.3
DEFAULT_AUTOCOMPLETE_LIMIT = 10
REBUILD_NEEDED = "is_autocomplete_multi_models_rebuild_needed"
DEFAULT_CAN_BE_INDEXED_BY_AUTOCOMPLETE_FUNCTION_NAME = "can_be_indexed_by_autocomplete"
AUTO_UPDATE_ENABLED = "is_autocomplete_auto_update_on_save_enabled"
def get_indexed_fields():
......
[metadata]
name = autocomplete-multi-models
version = 0.2
version = 0.3
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment