-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathdatetime_property.py.jinja
39 lines (34 loc) · 1.35 KB
/
datetime_property.py.jinja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{% macro construct_function(property, source) %}
isoparse({{ source }})
{% endmacro %}
{% from "property_templates/property_macros.py.jinja" import construct_template %}
{% macro construct(property, source) %}
{{ construct_template(construct_function, property, source) }}
{% endmacro %}
{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, str){% endmacro %}
{% macro transform(property, source, destination, declare_type=True) %}
{% set transformed = source + ".isoformat(timespec='seconds') + 'Z'" %}
{% if property.required %}
{{ destination }} = {{ transformed }}
{%- else %}
{% if declare_type %}
{% set type_annotation = property.get_type_string(json=True) %}
{{ destination }}: {{ type_annotation }} = UNSET
{% else %}
{{ destination }} = UNSET
{% endif %}
if not isinstance({{ source }}, Unset):
{{ destination }} = {{ transformed }}
{%- endif %}
{% endmacro %}
{% macro transform_multipart(property, source, destination) %}
{% set transformed = "(" + source + ".isoformat(timespec='seconds') + 'Z').encode()" %}
{% if property.required %}
{{ destination }} = {{ transformed }}
{%- else %}
{% set type_annotation = property.get_type_string(json=True) | replace("str", "bytes") %}
{{ destination }}: {{ type_annotation }} = UNSET
if not isinstance({{ source }}, Unset):
{{ destination }} = {{ transformed }}
{%- endif %}
{% endmacro %}