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.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-09-09 15:30:05 +03:00
parent 6539a63f4f
commit 2f4cceaa6a
3 changed files with 8 additions and 5 deletions

View file

@ -68,7 +68,7 @@ class SEOMetaType(ObjectType):
open_graph = GenericScalar() open_graph = GenericScalar()
twitter = GenericScalar() twitter = GenericScalar()
json_ld = List(GenericScalar) json_ld = List(GenericScalar)
hreflang = List(GenericScalar) hreflang = String()
class AttributeType(DjangoObjectType): class AttributeType(DjangoObjectType):
@ -173,7 +173,7 @@ class BrandType(DjangoObjectType):
"open_graph": og, "open_graph": og,
"twitter": tw, "twitter": tw,
"json_ld": json_ld, "json_ld": json_ld,
"hreflang": [], "hreflang": info.context.LANGUAGE_CODE,
} }
@ -336,7 +336,7 @@ class CategoryType(DjangoObjectType):
"open_graph": og, "open_graph": og,
"twitter": tw, "twitter": tw,
"json_ld": json_ld, "json_ld": json_ld,
"hreflang": [], "hreflang": info.context.LANGUAGE_CODE,
} }
@ -590,7 +590,7 @@ class ProductType(DjangoObjectType):
"open_graph": og, "open_graph": og,
"twitter": tw, "twitter": tw,
"json_ld": json_ld, "json_ld": json_ld,
"hreflang": [], "hreflang": info.context.LANGUAGE_CODE,
} }

View file

@ -7,7 +7,7 @@ class SeoSnapshotSerializer(Serializer):
description = CharField() description = CharField()
canonical = CharField() canonical = CharField()
robots = CharField() robots = CharField()
hreflang = ListField(child=DictField(), required=False) hreflang = CharField()
open_graph = DictField() open_graph = DictField()
twitter = DictField() twitter = DictField()
json_ld = ListField(child=DictField()) json_ld = ListField(child=DictField())

View file

@ -369,6 +369,7 @@ class CategoryViewSet(EvibesViewSet):
"description": description, "description": description,
"canonical": canonical, "canonical": canonical,
"robots": "index,follow", "robots": "index,follow",
"hreflang": request.LANGUAGE_CODE,
"open_graph": og, "open_graph": og,
"twitter": tw, "twitter": tw,
"json_ld": json_ld, "json_ld": json_ld,
@ -492,6 +493,7 @@ class BrandViewSet(EvibesViewSet):
"description": description, "description": description,
"canonical": canonical, "canonical": canonical,
"robots": "index,follow", "robots": "index,follow",
"hreflang": request.LANGUAGE_CODE,
"open_graph": og, "open_graph": og,
"twitter": tw, "twitter": tw,
"json_ld": json_ld, "json_ld": json_ld,
@ -618,6 +620,7 @@ class ProductViewSet(EvibesViewSet):
"description": description, "description": description,
"canonical": canonical, "canonical": canonical,
"robots": "index,follow", "robots": "index,follow",
"hreflang": request.LANGUAGE_CODE,
"open_graph": og, "open_graph": og,
"twitter": tw, "twitter": tw,
"json_ld": json_ld, "json_ld": json_ld,