From afff871783b490b1315f5bb5a20c6f6c7902aeb0 Mon Sep 17 00:00:00 2001 From: adamghill Date: Sat, 28 Oct 2023 16:48:54 -0400 Subject: [PATCH] Fix up `objects` example. --- example/unicorn/components/objects.py | 27 ++++++++++++------- .../unicorn/templates/unicorn/objects.html | 13 +++++++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/example/unicorn/components/objects.py b/example/unicorn/components/objects.py index 0212609f..d43d80c6 100644 --- a/example/unicorn/components/objects.py +++ b/example/unicorn/components/objects.py @@ -35,24 +35,30 @@ class PydanticBook(BaseModel): class ObjectsView(UnicornView): - unicorn_field = BookField() - pydantic_field = PydanticBook() - dictionary = {"name": "dictionary", "nested": {"name": "nested dictionary"}} - dictionary_2 = {"5": "a", "9": "b"} - book = Book(title="The Sandman") - books = Book.objects.all() + unicorn_field = None + pydantic_field = None + dictionary = None + dictionary_2 = None + book = None + books = None date_example = now() date_example_with_typehint: datetime = now() - dates_with_no_typehint = [] - dates_with_old_typehint: List[datetime] = [] - dates_with_new_typehint: list[datetime] = [] - dates_with_list_typehint: list = [] + dates_with_no_typehint = None + dates_with_old_typehint: List[datetime] = None + dates_with_new_typehint: list[datetime] = None + dates_with_list_typehint: list = None float_example: float = 1.1 decimal_example = D("1.1") int_example = 4 color = Color.RED def mount(self): + self.unicorn_field = BookField() + self.pydantic_field = PydanticBook() + self.dictionary = {"name": "dictionary", "nested": {"name": "nested dictionary"}} + self.dictionary2 = {"5": "a", "9": "b"} + self.book = Book(title="The Sandman") + self.books = Book.objects.all() self.dates_with_no_typehint = [datetime(2021, 1, 1), datetime(2021, 1, 2)] self.dates_with_old_typehint = [datetime(2022, 2, 1), datetime(2022, 2, 2)] self.dates_with_new_typehint = [datetime(2023, 3, 1), datetime(2023, 3, 2)] @@ -65,6 +71,7 @@ def check_date(self, dt: datetime): assert type(dt) is datetime self.date_example = dt + self.date_example_with_typehint = dt def add_hour(self): self.date_example_with_typehint = self.date_example_with_typehint + timedelta(hours=1) diff --git a/example/unicorn/templates/unicorn/objects.html b/example/unicorn/templates/unicorn/objects.html index 76cb6bb8..7c1e8d69 100644 --- a/example/unicorn/templates/unicorn/objects.html +++ b/example/unicorn/templates/unicorn/objects.html @@ -40,17 +40,26 @@
- + -
+ + +
+
{{ date_example_with_typehint }}
+ +
+
+ +
+
Dates list with no type hint (will change to strings with an action)