forked from DGNum/gestioCOF
Separate the autocompletion logic form the views
This commit is contained in:
parent
fbbc9937f6
commit
9a90f19502
12 changed files with 78 additions and 82 deletions
|
@ -1,7 +1,6 @@
|
|||
import logging
|
||||
from collections import namedtuple
|
||||
|
||||
from dal import autocomplete
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
|
||||
|
@ -100,14 +99,6 @@ class ModelSearch(SearchUnit):
|
|||
return self.model.objects.filter(self.get_queryset_filter(keywords))
|
||||
|
||||
|
||||
class Select2QuerySetView(ModelSearch, autocomplete.Select2QuerySetView):
|
||||
"""Compatibility layer between ModelSearch and Select2QuerySetView."""
|
||||
|
||||
def get_queryset(self):
|
||||
keywords = self.q.split()
|
||||
return super().search(keywords)
|
||||
|
||||
|
||||
# ---
|
||||
# LDAP search
|
||||
# ---
|
|
@ -44,7 +44,7 @@ class MockLDAPMixin:
|
|||
# Mock ldap module whose `initialize_method` always return the same ldap object.
|
||||
mock_ldap_module = self.MockLDAPModule(mock_ldap_obj)
|
||||
|
||||
patcher = mock.patch("shared.views.autocomplete.ldap", new=mock_ldap_module)
|
||||
patcher = mock.patch("shared.autocomplete.ldap", new=mock_ldap_module)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
|
|
11
shared/views.py
Normal file
11
shared/views.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from dal import autocomplete
|
||||
|
||||
from shared.autocomplete import ModelSearch
|
||||
|
||||
|
||||
class Select2QuerySetView(ModelSearch, autocomplete.Select2QuerySetView):
|
||||
"""Compatibility layer between ModelSearch and Select2QuerySetView."""
|
||||
|
||||
def get_queryset(self):
|
||||
keywords = self.q.split()
|
||||
return super().search(keywords)
|
Loading…
Add table
Add a link
Reference in a new issue