kopia lustrzana https://github.com/wagtail/wagtail
Move chooser views from search into searchpromotions
rodzic
019015c698
commit
a008554b9c
|
@ -153,14 +153,14 @@ module.exports = {
|
|||
files: [
|
||||
'docs/_static/**',
|
||||
'wagtail/contrib/modeladmin/static_src/wagtailmodeladmin/js/prepopulate.js',
|
||||
'wagtail/contrib/search_promotions/static_src/wagtailsearchpromotions/js/query-chooser-modal.js',
|
||||
'wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js',
|
||||
'wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/queries/chooser_field.js',
|
||||
'wagtail/documents/static_src/wagtaildocs/js/add-multiple.js',
|
||||
'wagtail/embeds/static_src/wagtailembeds/js/embed-chooser-modal.js',
|
||||
'wagtail/images/static_src/wagtailimages/js/add-multiple.js',
|
||||
'wagtail/images/static_src/wagtailimages/js/focal-point-chooser.js',
|
||||
'wagtail/images/static_src/wagtailimages/js/image-url-generator.js',
|
||||
'wagtail/search/static_src/wagtailsearch/js/query-chooser-modal.js',
|
||||
'wagtail/search/templates/wagtailsearch/queries/chooser_field.js',
|
||||
'wagtail/snippets/static_src/wagtailsnippets/js/snippet-multiple-select.js',
|
||||
'wagtail/users/static_src/wagtailusers/js/group-form.js',
|
||||
],
|
||||
|
|
|
@ -176,8 +176,8 @@ module.exports = function exports(env, argv) {
|
|||
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
||||
},
|
||||
{
|
||||
from: 'wagtail/search/static_src/',
|
||||
to: 'wagtail/search/static/',
|
||||
from: 'wagtail/contrib/search_promotions/static_src/',
|
||||
to: 'wagtail/contrib/search_promotions/static/',
|
||||
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
||||
},
|
||||
{
|
||||
|
|
|
@ -8,4 +8,10 @@ urlpatterns = [
|
|||
path("add/", views.add, name="add"),
|
||||
path("<int:query_id>/", views.edit, name="edit"),
|
||||
path("<int:query_id>/delete/", views.delete, name="delete"),
|
||||
path("queries/chooser/", views.chooser, name="chooser"),
|
||||
path(
|
||||
"queries/chooser/results/",
|
||||
views.chooserresults,
|
||||
name="chooserresults",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
<ul class="fields">
|
||||
<li>
|
||||
{% include "wagtailsearch/queries/chooser_field.html" with field=query_form.query_string only %}
|
||||
{% include "wagtailsearchpromotions/queries/chooser_field.html" with field=query_form.query_string only %}
|
||||
</li>
|
||||
<li>
|
||||
{% include "wagtailsearchpromotions/includes/searchpromotions_formset.html" with formset=searchpicks_formset only %}
|
||||
|
@ -39,12 +39,12 @@
|
|||
{% block extra_js %}
|
||||
{{ block.super }}
|
||||
{% include "wagtailadmin/pages/_editor_js.html" %}
|
||||
<script src="{% versioned_static 'wagtailsearch/js/query-chooser-modal.js' %}"></script>
|
||||
<script src="{% versioned_static 'wagtailsearchpromotions/js/query-chooser-modal.js' %}"></script>
|
||||
{{ form_media.js }}
|
||||
|
||||
<script type="text/javascript">
|
||||
{% include "wagtailsearchpromotions/includes/searchpromotions_formset.js" with formset=searchpicks_formset only %}
|
||||
{% include "wagtailsearch/queries/chooser_field.js" only %}
|
||||
{% include "wagtailsearchpromotions/queries/chooser_field.js" only %}
|
||||
|
||||
$(function() {
|
||||
createQueryChooser('{{ query_form.query_string.auto_id }}');
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<ul class="fields">
|
||||
<li>
|
||||
{% include "wagtailsearch/queries/chooser_field.html" with field=query_form.query_string only %}
|
||||
{% include "wagtailsearchpromotions/queries/chooser_field.html" with field=query_form.query_string only %}
|
||||
</li>
|
||||
<li>
|
||||
{% include "wagtailsearchpromotions/includes/searchpromotions_formset.html" with formset=searchpicks_formset only %}
|
||||
|
@ -30,12 +30,12 @@
|
|||
{% block extra_js %}
|
||||
{{ block.super }}
|
||||
{% include "wagtailadmin/pages/_editor_js.html" %}
|
||||
<script src="{% versioned_static 'wagtailsearch/js/query-chooser-modal.js' %}"></script>
|
||||
<script src="{% versioned_static 'wagtailsearchpromotions/js/query-chooser-modal.js' %}"></script>
|
||||
{{ form_media.js }}
|
||||
|
||||
<script type="text/javascript">
|
||||
{% include "wagtailsearchpromotions/includes/searchpromotions_formset.js" with formset=searchpicks_formset only %}
|
||||
{% include "wagtailsearch/queries/chooser_field.js" only %}
|
||||
{% include "wagtailsearchpromotions/queries/chooser_field.js" only %}
|
||||
|
||||
$(function() {
|
||||
createQueryChooser('{{ query_form.query_string.auto_id }}');
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{% include "wagtailadmin/shared/header.html" with title=pop_str %}
|
||||
|
||||
<div class="nice-padding">
|
||||
<form class="query-search full-width" action="{% url 'wagtailsearch_admin:queries_chooserresults' %}" method="GET" autocomplete="off" novalidate>
|
||||
<form class="query-search full-width" action="{% url 'wagtailsearchpromotions:chooserresults' %}" method="GET" autocomplete="off" novalidate>
|
||||
<ul class="fields">
|
||||
{% for field in searchform %}
|
||||
<li>
|
||||
|
@ -15,6 +15,6 @@
|
|||
</form>
|
||||
|
||||
<div id="query-results">
|
||||
{% include "wagtailsearch/queries/chooser/results.html" %}
|
||||
{% include "wagtailsearchpromotions/queries/chooser/results.html" %}
|
||||
</div>
|
||||
</div>
|
|
@ -3,7 +3,7 @@ function createQueryChooser(id) {
|
|||
var input = $('#' + id);
|
||||
|
||||
chooserElement.on('click', function () {
|
||||
var initialUrl = '{% url "wagtailsearch_admin:queries_chooser" %}';
|
||||
var initialUrl = '{% url "wagtailsearchpromotions:chooser" %}';
|
||||
|
||||
ModalWorkflow({
|
||||
url: initialUrl,
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
from datetime import date, datetime, timedelta
|
||||
from io import StringIO
|
||||
|
||||
|
@ -767,3 +768,32 @@ class TestCopyDailyHitsFromWagtailSearchManagementCommand(TestCase):
|
|||
|
||||
# Check daily hits
|
||||
self.assertEqual(new_query.hits, 3)
|
||||
|
||||
|
||||
class TestQueryChooserView(WagtailTestUtils, TestCase):
|
||||
def setUp(self):
|
||||
self.login()
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get("/admin/searchpicks/queries/chooser/", params)
|
||||
|
||||
def test_simple(self):
|
||||
response = self.get()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(
|
||||
response, "wagtailsearchpromotions/queries/chooser/chooser.html"
|
||||
)
|
||||
response_json = json.loads(response.content.decode())
|
||||
self.assertEqual(response_json["step"], "chooser")
|
||||
|
||||
def test_search(self):
|
||||
response = self.get({"q": "Hello"})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_pagination(self):
|
||||
# page numbers in range should be accepted
|
||||
response = self.get({"p": 1})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
# page numbers out of range should return 404
|
||||
response = self.get({"p": 9999})
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
|
|
@ -11,9 +11,11 @@ from django.views.decorators.vary import vary_on_headers
|
|||
from wagtail.admin import messages
|
||||
from wagtail.admin.auth import any_permission_required, permission_required
|
||||
from wagtail.admin.forms.search import SearchForm
|
||||
from wagtail.contrib.search_promotions import forms
|
||||
from wagtail.admin.modal_workflow import render_modal_workflow
|
||||
from wagtail.contrib.search_promotions import forms, models
|
||||
from wagtail.contrib.search_promotions.models import Query
|
||||
from wagtail.log_actions import log
|
||||
from wagtail.search.utils import normalise_query_string
|
||||
|
||||
|
||||
@any_permission_required(
|
||||
|
@ -260,3 +262,50 @@ def delete(request, query_id):
|
|||
"query": query,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def chooser(request, get_results=False):
|
||||
# Get most popular queries
|
||||
queries = models.Query.get_most_popular()
|
||||
|
||||
# If searching, filter results by query string
|
||||
if "q" in request.GET:
|
||||
searchform = SearchForm(request.GET)
|
||||
if searchform.is_valid():
|
||||
query_string = searchform.cleaned_data["q"]
|
||||
queries = queries.filter(
|
||||
query_string__icontains=normalise_query_string(query_string)
|
||||
)
|
||||
else:
|
||||
searchform = SearchForm()
|
||||
|
||||
paginator = Paginator(queries, per_page=10)
|
||||
try:
|
||||
queries = paginator.page(request.GET.get("p", 1))
|
||||
except InvalidPage:
|
||||
raise Http404
|
||||
|
||||
# Render
|
||||
if get_results:
|
||||
return TemplateResponse(
|
||||
request,
|
||||
"wagtailsearchpromotions/queries/chooser/results.html",
|
||||
{
|
||||
"queries": queries,
|
||||
},
|
||||
)
|
||||
else:
|
||||
return render_modal_workflow(
|
||||
request,
|
||||
"wagtailsearchpromotions/queries/chooser/chooser.html",
|
||||
None,
|
||||
{
|
||||
"queries": queries,
|
||||
"searchform": searchform,
|
||||
},
|
||||
json_data={"step": "chooser"},
|
||||
)
|
||||
|
||||
|
||||
def chooserresults(request):
|
||||
return chooser(request, get_results=True)
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
import datetime
|
||||
import json
|
||||
from io import StringIO
|
||||
|
||||
from django.core import management
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
|
||||
|
@ -13,7 +9,6 @@ from wagtail.search.utils import (
|
|||
parse_query_string,
|
||||
separate_filters_from_query,
|
||||
)
|
||||
from wagtail.test.utils import WagtailTestUtils
|
||||
|
||||
|
||||
class TestHitCounter(TestCase):
|
||||
|
@ -157,33 +152,6 @@ class TestGarbageCollectCommand(TestCase):
|
|||
)
|
||||
|
||||
|
||||
class TestQueryChooserView(WagtailTestUtils, TestCase):
|
||||
def setUp(self):
|
||||
self.login()
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get("/admin/search/queries/chooser/", params)
|
||||
|
||||
def test_simple(self):
|
||||
response = self.get()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, "wagtailsearch/queries/chooser/chooser.html")
|
||||
response_json = json.loads(response.content.decode())
|
||||
self.assertEqual(response_json["step"], "chooser")
|
||||
|
||||
def test_search(self):
|
||||
response = self.get({"q": "Hello"})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_pagination(self):
|
||||
# page numbers in range should be accepted
|
||||
response = self.get({"p": 1})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
# page numbers out of range should return 404
|
||||
response = self.get({"p": 9999})
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
class TestSeparateFiltersFromQuery(SimpleTestCase):
|
||||
def test_only_query(self):
|
||||
filters, query = separate_filters_from_query("hello world")
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
from django.urls import path
|
||||
|
||||
from wagtail.search.views import queries
|
||||
|
||||
app_name = "wagtailsearch_admin"
|
||||
urlpatterns = [
|
||||
path("queries/chooser/", queries.chooser, name="queries_chooser"),
|
||||
path(
|
||||
"queries/chooser/results/",
|
||||
queries.chooserresults,
|
||||
name="queries_chooserresults",
|
||||
),
|
||||
]
|
|
@ -1,55 +0,0 @@
|
|||
from django.core.paginator import InvalidPage, Paginator
|
||||
from django.http import Http404
|
||||
from django.template.response import TemplateResponse
|
||||
|
||||
from wagtail.admin.forms.search import SearchForm
|
||||
from wagtail.admin.modal_workflow import render_modal_workflow
|
||||
from wagtail.search import models
|
||||
from wagtail.search.utils import normalise_query_string
|
||||
|
||||
|
||||
def chooser(request, get_results=False):
|
||||
# Get most popular queries
|
||||
queries = models.Query.get_most_popular()
|
||||
|
||||
# If searching, filter results by query string
|
||||
if "q" in request.GET:
|
||||
searchform = SearchForm(request.GET)
|
||||
if searchform.is_valid():
|
||||
query_string = searchform.cleaned_data["q"]
|
||||
queries = queries.filter(
|
||||
query_string__icontains=normalise_query_string(query_string)
|
||||
)
|
||||
else:
|
||||
searchform = SearchForm()
|
||||
|
||||
paginator = Paginator(queries, per_page=10)
|
||||
try:
|
||||
queries = paginator.page(request.GET.get("p", 1))
|
||||
except InvalidPage:
|
||||
raise Http404
|
||||
|
||||
# Render
|
||||
if get_results:
|
||||
return TemplateResponse(
|
||||
request,
|
||||
"wagtailsearch/queries/chooser/results.html",
|
||||
{
|
||||
"queries": queries,
|
||||
},
|
||||
)
|
||||
else:
|
||||
return render_modal_workflow(
|
||||
request,
|
||||
"wagtailsearch/queries/chooser/chooser.html",
|
||||
None,
|
||||
{
|
||||
"queries": queries,
|
||||
"searchform": searchform,
|
||||
},
|
||||
json_data={"step": "chooser"},
|
||||
)
|
||||
|
||||
|
||||
def chooserresults(request):
|
||||
return chooser(request, get_results=True)
|
|
@ -1,11 +0,0 @@
|
|||
from django.urls import include, path
|
||||
|
||||
from wagtail import hooks
|
||||
from wagtail.search.urls import admin as admin_urls
|
||||
|
||||
|
||||
@hooks.register("register_admin_urls")
|
||||
def register_admin_urls():
|
||||
return [
|
||||
path("search/", include(admin_urls, namespace="wagtailsearch_admin")),
|
||||
]
|
Ładowanie…
Reference in New Issue