Move QueryForm into searchpromotions

pull/10161/head^2
Karl Hobley 2021-06-22 16:39:48 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic 751032a16d
commit 2817fec9fc
3 zmienionych plików z 27 dodań i 19 usunięć

Wyświetl plik

@ -6,6 +6,18 @@ from wagtail.admin.widgets import AdminPageChooser
from wagtail.contrib.search_promotions.models import Query, SearchPromotion
class QueryForm(forms.Form):
query_string = forms.CharField(
label=_("Search term(s)/phrase"),
help_text=_(
"Enter the full search string to match. An "
"exact match is required for your Promoted Results to be "
"displayed, wildcards are NOT allowed."
),
required=True,
)
class SearchPromotionForm(forms.ModelForm):
sort_order = forms.IntegerField(required=False)

Wyświetl plik

@ -13,7 +13,6 @@ from wagtail.admin.forms.search import SearchForm
from wagtail.contrib.search_promotions import forms
from wagtail.contrib.search_promotions.models import Query
from wagtail.log_actions import log
from wagtail.search import forms as search_forms
@any_permission_required(
@ -124,7 +123,7 @@ def save_searchpicks(query, new_query, searchpicks_formset):
def add(request):
if request.method == "POST":
# Get query
query_form = search_forms.QueryForm(request.POST)
query_form = forms.QueryForm(request.POST)
if query_form.is_valid():
query = Query.get(query_form["query_string"].value())
@ -164,7 +163,7 @@ def add(request):
else:
searchpicks_formset = forms.SearchPromotionsFormSet()
else:
query_form = search_forms.QueryForm()
query_form = forms.QueryForm()
searchpicks_formset = forms.SearchPromotionsFormSet()
return TemplateResponse(
@ -184,7 +183,7 @@ def edit(request, query_id):
if request.method == "POST":
# Get query
query_form = search_forms.QueryForm(request.POST)
query_form = forms.QueryForm(request.POST)
# and the recommendations
searchpicks_formset = forms.SearchPromotionsFormSet(
request.POST, instance=query
@ -222,9 +221,7 @@ def edit(request, query_id):
# specific errors will be displayed within form fields
else:
query_form = search_forms.QueryForm(
initial={"query_string": query.query_string}
)
query_form = forms.QueryForm(initial={"query_string": query.query_string})
searchpicks_formset = forms.SearchPromotionsFormSet(instance=query)
return TemplateResponse(

Wyświetl plik

@ -1,14 +1,13 @@
from django import forms
from django.utils.translation import gettext_lazy as _
import sys
from wagtail.utils.deprecation import MovedDefinitionHandler, RemovedInWagtail60Warning
class QueryForm(forms.Form):
query_string = forms.CharField(
label=_("Search term(s)/phrase"),
help_text=_(
"Enter the full search string to match. An "
"exact match is required for your Promoted Results to be "
"displayed, wildcards are NOT allowed."
),
required=True,
)
MOVED_DEFINITIONS = {
"QueryForm": ("wagtail.contrib.search_promotions.forms", "QueryForm"),
}
sys.modules[__name__] = MovedDefinitionHandler(
sys.modules[__name__],
MOVED_DEFINITIONS,
RemovedInWagtail60Warning,
)