Features: 1) Add absolute URI resolution for image in Category and ProductImage.

Fixes: 1) Ensure fallback to empty string when `image` is None in `Category` and `ProductImage`.

Extra: Refactored `resolve_image` methods for improved URL handling.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-11-12 12:53:28 +03:00
parent 59b09c40f6
commit 9632915593

View file

@ -235,7 +235,7 @@ class CategoryType(DjangoObjectType): # type: ignore [misc]
return result return result
def resolve_image(self: Category, info) -> str: def resolve_image(self: Category, info) -> str:
return self.image_url return info.context.build_absolute_uri(self.image.url) if self.image else ""
def resolve_markup_percent(self: Category, info) -> float: def resolve_markup_percent(self: Category, info) -> float:
if info.context.user.has_perm("core.view_category"): if info.context.user.has_perm("core.view_category"):
@ -466,8 +466,8 @@ class ProductImageType(DjangoObjectType): # type: ignore [misc]
filter_fields = ["uuid"] filter_fields = ["uuid"]
description = _("product's images") description = _("product's images")
def resolve_image(self: ProductImage, _info): def resolve_image(self: ProductImage, info):
return self.image_url return info.context.build_absolute_uri(self.image.url) if self.image else ""
class ProductType(DjangoObjectType): # type: ignore [misc] class ProductType(DjangoObjectType): # type: ignore [misc]