Skip to content

Commit afff871

Browse files
committed
Fix up objects example.
1 parent d46232f commit afff871

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

example/unicorn/components/objects.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,30 @@ class PydanticBook(BaseModel):
3535

3636

3737
class ObjectsView(UnicornView):
38-
unicorn_field = BookField()
39-
pydantic_field = PydanticBook()
40-
dictionary = {"name": "dictionary", "nested": {"name": "nested dictionary"}}
41-
dictionary_2 = {"5": "a", "9": "b"}
42-
book = Book(title="The Sandman")
43-
books = Book.objects.all()
38+
unicorn_field = None
39+
pydantic_field = None
40+
dictionary = None
41+
dictionary_2 = None
42+
book = None
43+
books = None
4444
date_example = now()
4545
date_example_with_typehint: datetime = now()
46-
dates_with_no_typehint = []
47-
dates_with_old_typehint: List[datetime] = []
48-
dates_with_new_typehint: list[datetime] = []
49-
dates_with_list_typehint: list = []
46+
dates_with_no_typehint = None
47+
dates_with_old_typehint: List[datetime] = None
48+
dates_with_new_typehint: list[datetime] = None
49+
dates_with_list_typehint: list = None
5050
float_example: float = 1.1
5151
decimal_example = D("1.1")
5252
int_example = 4
5353
color = Color.RED
5454

5555
def mount(self):
56+
self.unicorn_field = BookField()
57+
self.pydantic_field = PydanticBook()
58+
self.dictionary = {"name": "dictionary", "nested": {"name": "nested dictionary"}}
59+
self.dictionary2 = {"5": "a", "9": "b"}
60+
self.book = Book(title="The Sandman")
61+
self.books = Book.objects.all()
5662
self.dates_with_no_typehint = [datetime(2021, 1, 1), datetime(2021, 1, 2)]
5763
self.dates_with_old_typehint = [datetime(2022, 2, 1), datetime(2022, 2, 2)]
5864
self.dates_with_new_typehint = [datetime(2023, 3, 1), datetime(2023, 3, 2)]
@@ -65,6 +71,7 @@ def check_date(self, dt: datetime):
6571
assert type(dt) is datetime
6672

6773
self.date_example = dt
74+
self.date_example_with_typehint = dt
6875

6976
def add_hour(self):
7077
self.date_example_with_typehint = self.date_example_with_typehint + timedelta(hours=1)

example/unicorn/templates/unicorn/objects.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,26 @@
4040
</div>
4141
<div>
4242
<button u:click='get_date'>get_date</button>
43-
<button u:click='check_date("2020-09-12T01:01:01")'>check_date static</button>
43+
<button u:click='check_date("2020-09-12T01:01:01")'>check_date static string</button>
4444
<button u:click='check_date("{{ date_example|date:'c' }}")'>check_date (c)</button>
45-
<button u:click='check_date({{ date_example|date:'U' }})'>check_date (U)</button>
4645
</div>
46+
</div>
47+
48+
<div>
49+
<label>Datetime with type hint</label>
4750

4851
<div>
4952
{{ date_example_with_typehint }}
5053
</div>
5154
<div>
55+
<button u:click='check_date("{{ date_example_with_typehint|date:'c' }}")'>check_date (c)</button>
56+
<button u:click='check_date({{ date_example_with_typehint|date:'U' }})'>check_date (U)</button>
5257
<button u:click='add_hour()'>add_hour()</button>
5358
</div>
59+
</div>
60+
61+
<div>
62+
<label>Datetimes in a list</label>
5463

5564
<div>
5665
<div>Dates list with no type hint (will change to strings with an action)</div>

0 commit comments

Comments
 (0)