-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add patch to Snippet chooser to customize search
With this patch installed, the snippet chooser checks for a method `chooser_search` in the model. If it exists, this method is used instead of the search backend.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
patches/Wagtail-Snippet-Chooser-Call-search-method-from-model-if-available.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
From 7b829bfdcd151a256788b99276db0566983b1ee6 Mon Sep 17 00:00:00 2001 | ||
From: Donald Buczek <buczek@molgen.mpg.de> | ||
Date: Fri, 14 Aug 2020 22:55:59 +0200 | ||
Subject: [PATCH] Chooser: Call search method from model if available | ||
|
||
--- | ||
.../site-packages/wagtail/snippets/views/chooser.py | 5 ++++- | ||
1 file changed, 4 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/lib/python3.7/site-packages/wagtail/snippets/views/chooser.py b/lib/python3.7/site-packages/wagtail/snippets/views/chooser.py | ||
index 7c93edd..26606cd 100644 | ||
--- a/lib/python3.7/site-packages/wagtail/snippets/views/chooser.py | ||
+++ b/lib/python3.7/site-packages/wagtail/snippets/views/chooser.py | ||
@@ -35,7 +35,10 @@ def choose(request, app_label, model_name): | ||
search_query = search_form.cleaned_data['q'] | ||
|
||
search_backend = get_search_backend() | ||
- items = search_backend.search(search_query, items) | ||
+ if callable(getattr(model, "chooser_search", None)): | ||
+ items = model.chooser_search(search_query) | ||
+ else: | ||
+ items = search_backend.search(search_query, items) | ||
is_searching = True | ||
|
||
else: | ||
-- | ||
2.26.2 | ||
|