Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow missing image files and wagtailimages_serve view in ImageType #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions wagtail_graphql/types/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from graphql.execution.base import ResolveInfo
# django
from django.urls import reverse
from django.urls import NoReverseMatch
# graphene
import graphene
# graphene_django
Expand All @@ -11,6 +12,7 @@
import graphene_django_optimizer as gql_optimizer
# wagtail images
from wagtail.images.models import Image as wagtailImage
from wagtail.images.shortcuts import get_rendition_or_not_found
from wagtail.images.views.serve import generate_signature
# app
from ..permissions import with_collection_permissions
Expand Down Expand Up @@ -75,13 +77,16 @@ def resolve_url_link(self: wagtailImage, _info: ResolveInfo, rendition: str = No
else:
fp = self.get_focal_point()
rendition = 'fill-%dx%d-c100' % (fp.width, fp.height)
return self.get_rendition(rendition).url
return get_rendition_or_not_found(self, rendition).url


def generate_image_url(image: wagtailImage, filter_spec: str) -> str:
signature = generate_signature(image.pk, filter_spec)
url = reverse('wagtailimages_serve', args=(signature, image.pk, filter_spec))
return url
try:
url = reverse('wagtailimages_serve', args=(signature, image.pk, filter_spec))
return url
except NoReverseMatch:
return None


def ImageQueryMixin():
Expand Down