On the contract template, the hours and the dates were not rendered as expected once it was generated.
To avoid facing this situation, we now transform those values of dates and duration into iso 8601 string format before returning the context. We want the value to be prepared at their creation before adding it to the contract.
Overall, we had to update the : course_start, course_end, course_effort and course_price.
Purpose
Make sure that our template tags for date and duration iso 8601 will work as expected into the template rendering. They are both waiting for the incoming input value to be strings and not datetime.datetime, or datetime.date, and not datetime.timedelta.
Proposal
[x] Adjust def generate_context_document() utility method in contract_definition.py
[x] add a model test where we verify how the context is build when calling submit_for_signature
[x] add test on utility method generate_document_context
Since we prepare the context that way it should be saved into the contract.context, we should also make sure the "order.total" is the string of the Decimal value, else this error comes up if we don't force the order.price to string representation in the generation of the context.
self = <json.encoder.JSONEncoder object at 0x711ffe726cb0>, o = Decimal('999.99')
def default(self, o):
"""Implement this method in a subclass such that it returns
a serializable object for ``o``, or calls the base implementation
(to raise a ``TypeError``).
For example, to support arbitrary iterators, you could
implement default like this::
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
# Let the base class default method raise the TypeError
return JSONEncoder.default(self, o)
"""
> raise TypeError(f'Object of type {o.__class__.__name__} '
f'is not JSON serializable')
E TypeError: Object of type Decimal is not JSON serializable
On the contract template, the hours and the dates were not rendered as expected once it was generated.
To avoid facing this situation, we now transform those values of dates and duration into iso 8601 string format before returning the context. We want the value to be prepared at their creation before adding it to the contract.
Overall, we had to update the :
course_start
,course_end
,course_effort
andcourse_price
.Purpose
Make sure that our template tags for date and duration iso 8601 will work as expected into the template rendering. They are both waiting for the incoming input value to be strings and not datetime.datetime, or datetime.date, and not datetime.timedelta.
Proposal
def generate_context_document()
utility method incontract_definition.py
submit_for_signature
generate_document_context
Since we prepare the context that way it should be saved into the
contract.context
, we should also make sure the "order.total" is the string of the Decimal value, else this error comes up if we don't force theorder.price
to string representation in the generation of the context.