Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-autocomplete-multi-models
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hub
django-autocomplete-multi-models
Commits
a6e08d3c
Commit
a6e08d3c
authored
2 years ago
by
Bryan BRANCOTTE
Browse files
Options
Downloads
Patches
Plain Diff
allows to add integer field to index, prevent substring that are integer to be added
parent
054f6461
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
autocomplete_multi_models/business_process.py
+3
-2
3 additions, 2 deletions
autocomplete_multi_models/business_process.py
autocomplete_multi_models/tests/test_business_process.py
+14
-0
14 additions, 0 deletions
autocomplete_multi_models/tests/test_business_process.py
with
17 additions
and
2 deletions
autocomplete_multi_models/business_process.py
+
3
−
2
View file @
a6e08d3c
...
...
@@ -80,7 +80,7 @@ def _add_instance_to_index(instance, field_names: List[str], objects: list, curs
if
f
and
not
f
():
return
for
field_name
in
field_names
:
_add_text_to_index
(
getattr
(
instance
,
field_name
),
objects
,
cursor
)
_add_text_to_index
(
str
(
getattr
(
instance
,
field_name
)
)
,
objects
,
cursor
)
def
add_text_to_index
(
value
:
str
):
...
...
@@ -120,9 +120,10 @@ def _purge_banned_words():
def
_add_text_to_index
(
value
:
str
,
objects
:
list
,
cursor
):
if
value
is
None
or
value
==
''
:
return
len_value
=
len
(
value
)
for
word
in
split_string
(
value
):
len_word
=
len
(
word
)
if
len_word
<
_AUTOCOMPLETE_MIN_LENGTH
or
word
.
isdecimal
()
or
len_word
>
64
:
if
len_word
<
_AUTOCOMPLETE_MIN_LENGTH
or
(
len_word
!=
len_value
and
word
.
isdecimal
()
)
or
len_word
>
64
:
continue
cursor
.
execute
(
"
SELECT UPPER(UNACCENT(%s)) as value
"
,
[
word
])
ac_word
=
cursor
.
fetchone
()[
0
]
...
...
This diff is collapsed.
Click to expand it.
autocomplete_multi_models/tests/test_business_process.py
+
14
−
0
View file @
a6e08d3c
...
...
@@ -135,6 +135,20 @@ class BannedWord(test_helpers.ChangeAutoCompleteSettingsTestCase):
self
.
assertEqual
(
models
.
IndexedWord
.
objects
.
count
(),
3
)
@override_settings
(
AUTOCOMPLETE_MIN_LENGTH
=
1
)
class
SubIntNotAdded
(
test_helpers
.
ChangeAutoCompleteSettingsTestCase
):
def
test_it
(
self
):
business_process
.
add_text_to_index
(
"
00001101 AAAA ZZZZ EEEE
"
)
self
.
assertEqual
(
models
.
IndexedWord
.
objects
.
count
(),
3
)
@override_settings
(
AUTOCOMPLETE_MIN_LENGTH
=
1
)
class
CompleteIntAdded
(
test_helpers
.
ChangeAutoCompleteSettingsTestCase
):
def
test_it
(
self
):
business_process
.
add_text_to_index
(
"
0000110
"
)
self
.
assertEqual
(
models
.
IndexedWord
.
objects
.
count
(),
1
)
@override_settings
(
AUTOCOMPLETE_PERSISTENT_VARIABLE_GETTER_SETTER
=
None
)
class
NeedRebuildDefaultBehaviorTestCase
(
test_helpers
.
ChangeAutoCompleteSettingsTestCase
):
def
test_it
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment