From f691669d76690f84753f2d1fdbf88a5d51e783cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20S=C3=A9chet?= Date: Mon, 20 May 2024 21:43:19 +0200 Subject: [PATCH] feat: add accessor and iterator method on data field --- jwebsite/content.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jwebsite/content.py b/jwebsite/content.py index 5d15942..a40e801 100644 --- a/jwebsite/content.py +++ b/jwebsite/content.py @@ -56,6 +56,13 @@ class DataField: def __str__(self) -> str: return str(self.__value) + def __getitem__(self, key: Any) -> Any: + return DataField(self.__file, self.__value.get(key)) + + def __iter__(self) -> Iterator[Any]: + for it in self.__value: + yield DataField(self.__file, it) + class DataFile(Content): def __init__(self, path: Path) -> None: