Skip to content

Commit

Permalink
Fix up objects example.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamghill committed Oct 28, 2023
1 parent d46232f commit afff871
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
27 changes: 17 additions & 10 deletions example/unicorn/components/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions example/unicorn/templates/unicorn/objects.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,26 @@
</div>
<div>
<button u:click='get_date'>get_date</button>
<button u:click='check_date("2020-09-12T01:01:01")'>check_date static</button>
<button u:click='check_date("2020-09-12T01:01:01")'>check_date static string</button>
<button u:click='check_date("{{ date_example|date:'c' }}")'>check_date (c)</button>
<button u:click='check_date({{ date_example|date:'U' }})'>check_date (U)</button>
</div>
</div>

<div>
<label>Datetime with type hint</label>

<div>
{{ date_example_with_typehint }}
</div>
<div>
<button u:click='check_date("{{ date_example_with_typehint|date:'c' }}")'>check_date (c)</button>
<button u:click='check_date({{ date_example_with_typehint|date:'U' }})'>check_date (U)</button>
<button u:click='add_hour()'>add_hour()</button>
</div>
</div>

<div>
<label>Datetimes in a list</label>

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

0 comments on commit afff871

Please sign in to comment.