Skip to content

Commit

Permalink
fix resolve_rendition, instantiating ImageRenditionObjectType by hand?!
Browse files Browse the repository at this point in the history
this fixes torchbox#318
  • Loading branch information
engAmirEng committed May 15, 2023
1 parent b4e256c commit 5fdc008
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
13 changes: 1 addition & 12 deletions grapple/types/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,10 @@ def resolve_rendition(self, info, **kwargs):
# Only allowed the defined filters (thus renditions)
if rendition_allowed(filters):
try:
img = self.get_rendition(filters)
return self.get_rendition(filters)
except SourceImageIOError:
return

rendition_type = get_rendition_type()

return rendition_type(
id=img.id,
url=get_media_item_url(img),
width=img.width,
height=img.height,
file=img.file,
image=self,
)

def resolve_src_set(self, info, sizes, format=None, **kwargs):
"""
Generate src set of renditions.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_grapple.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ def test_renditions(self):
image(id: %d) {
rendition(width: 100) {
url
customRenditionProperty
}
}
}
Expand All @@ -1044,6 +1045,7 @@ def test_renditions(self):

executed = self.client.execute(query)
self.assertIn("width-100", executed["data"]["image"]["rendition"]["url"])
self.assertIn("Rendition Model!", executed["data"]["image"]["rendition"]["customRenditionProperty"])

@override_settings(GRAPPLE={"ALLOWED_IMAGE_FILTERS": ["width-200"]})
def test_renditions_with_allowed_image_filters_restrictions(self):
Expand Down

0 comments on commit 5fdc008

Please sign in to comment.