From 2f4cceaa6aaf455096a633bd9b19a5b642658495 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Tue, 9 Sep 2025 15:30:05 +0300 Subject: [PATCH] Features: 1) Add `hreflang` to metadata response across viewsets; 2) Update GraphQL schema to use `hreflang` as a string instead of a list. Fixes: 1) Correct `hreflang` field type in serializers and GraphQL object types. Extra: Refactor redundant `hreflang` handling; ensure uniform `LANGUAGE_CODE` usage throughout. --- core/graphene/object_types.py | 8 ++++---- core/serializers/seo.py | 2 +- core/viewsets.py | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/graphene/object_types.py b/core/graphene/object_types.py index 9bfedf9a..1106fd63 100644 --- a/core/graphene/object_types.py +++ b/core/graphene/object_types.py @@ -68,7 +68,7 @@ class SEOMetaType(ObjectType): open_graph = GenericScalar() twitter = GenericScalar() json_ld = List(GenericScalar) - hreflang = List(GenericScalar) + hreflang = String() class AttributeType(DjangoObjectType): @@ -173,7 +173,7 @@ class BrandType(DjangoObjectType): "open_graph": og, "twitter": tw, "json_ld": json_ld, - "hreflang": [], + "hreflang": info.context.LANGUAGE_CODE, } @@ -336,7 +336,7 @@ class CategoryType(DjangoObjectType): "open_graph": og, "twitter": tw, "json_ld": json_ld, - "hreflang": [], + "hreflang": info.context.LANGUAGE_CODE, } @@ -590,7 +590,7 @@ class ProductType(DjangoObjectType): "open_graph": og, "twitter": tw, "json_ld": json_ld, - "hreflang": [], + "hreflang": info.context.LANGUAGE_CODE, } diff --git a/core/serializers/seo.py b/core/serializers/seo.py index 780d25a5..046fa1c7 100644 --- a/core/serializers/seo.py +++ b/core/serializers/seo.py @@ -7,7 +7,7 @@ class SeoSnapshotSerializer(Serializer): description = CharField() canonical = CharField() robots = CharField() - hreflang = ListField(child=DictField(), required=False) + hreflang = CharField() open_graph = DictField() twitter = DictField() json_ld = ListField(child=DictField()) diff --git a/core/viewsets.py b/core/viewsets.py index df27c738..cc802cc8 100644 --- a/core/viewsets.py +++ b/core/viewsets.py @@ -369,6 +369,7 @@ class CategoryViewSet(EvibesViewSet): "description": description, "canonical": canonical, "robots": "index,follow", + "hreflang": request.LANGUAGE_CODE, "open_graph": og, "twitter": tw, "json_ld": json_ld, @@ -492,6 +493,7 @@ class BrandViewSet(EvibesViewSet): "description": description, "canonical": canonical, "robots": "index,follow", + "hreflang": request.LANGUAGE_CODE, "open_graph": og, "twitter": tw, "json_ld": json_ld, @@ -618,6 +620,7 @@ class ProductViewSet(EvibesViewSet): "description": description, "canonical": canonical, "robots": "index,follow", + "hreflang": request.LANGUAGE_CODE, "open_graph": og, "twitter": tw, "json_ld": json_ld,