This commit is contained in:
@@ -5,6 +5,7 @@ from grapple.models import (
|
|||||||
GraphQLString,
|
GraphQLString,
|
||||||
)
|
)
|
||||||
from wagtail.images.models import AbstractImage, AbstractRendition, Image
|
from wagtail.images.models import AbstractImage, AbstractRendition, Image
|
||||||
|
from wagtail.search import index
|
||||||
|
|
||||||
|
|
||||||
class CustomImage(AbstractImage):
|
class CustomImage(AbstractImage):
|
||||||
@@ -48,6 +49,15 @@ class CustomImage(AbstractImage):
|
|||||||
GraphQLString("attribution"),
|
GraphQLString("attribution"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Wagtail indexes title, description and tags. Editors describe the picture
|
||||||
|
# in `alt` rather than in `description`, so it is boosted alongside title.
|
||||||
|
search_fields = AbstractImage.search_fields + [
|
||||||
|
index.SearchField("alt", boost=10),
|
||||||
|
index.AutocompleteField("alt"),
|
||||||
|
index.SearchField("attribution"),
|
||||||
|
index.AutocompleteField("attribution"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Rendition(AbstractRendition):
|
class Rendition(AbstractRendition):
|
||||||
image = models.ForeignKey(CustomImage, on_delete=models.CASCADE, related_name="renditions")
|
image = models.ForeignKey(CustomImage, on_delete=models.CASCADE, related_name="renditions")
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
from wagtail.search.index import class_is_indexed
|
from wagtail.search.index import class_is_indexed
|
||||||
|
|
||||||
from images.models import CustomImage
|
from images.models import CustomImage
|
||||||
@@ -33,6 +35,21 @@ def test_admin_image_chooser_search_filters_results(admin_client, db):
|
|||||||
assert [image.title for image in response.context["results"]] == ["Portrett av Jahn Teigen"]
|
assert [image.title for image in response.context["results"]] == ["Portrett av Jahn Teigen"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("term", ["Konsertbilde", "Stemningsbilde", "Teigen", "Nordmann"])
|
||||||
|
def test_admin_image_listing_searches_alt_and_attribution(admin_client, db, term):
|
||||||
|
CustomImageFactory(
|
||||||
|
title="Konsertbilde fra Betong",
|
||||||
|
description="Stemningsbilde fra scenen",
|
||||||
|
alt="Portrettbilde av Jahn Teigen",
|
||||||
|
attribution="Foto: Kari Nordmann",
|
||||||
|
)
|
||||||
|
CustomImageFactory(title="Et annet bilde")
|
||||||
|
|
||||||
|
response = admin_client.get("/admin/images/", {"q": term})
|
||||||
|
|
||||||
|
assert [image.title for image in response.context["page_obj"]] == ["Konsertbilde fra Betong"]
|
||||||
|
|
||||||
|
|
||||||
def test_public_images_field_has_no_search_argument(graphql_post):
|
def test_public_images_field_has_no_search_argument(graphql_post):
|
||||||
_, body = graphql_post('{ __type(name: "Query") { fields { name args { name } } } }')
|
_, body = graphql_post('{ __type(name: "Query") { fields { name args { name } } } }')
|
||||||
args = {
|
args = {
|
||||||
|
|||||||
Reference in New Issue
Block a user