Templating🔗
The Python app has a templating feature using the Django templating engine. You can use Django's templating language to generate dynamic URLs based on user input and/or current time.
Usage🔗
To use this feature, you can input a JSON configuration which can contain Django templating expressions.
Here's an example input:
{
"url": "https://vnvsa.teamwork.com/time_entries.json?fromdate={{now|replace_time:'1d0h0m0s'|date:'Y-m-d'}}&todate={{now|replace_time:'1d0h0m0s'|add_time:'1M'|date:'Y-m-d'}}&fromtime={{now|replace_time:'1M1d0h0m0s'|date:'H:i'}}&totime={{now|replace_time:'1d0h0m0s'|add_time:'1M'|date:'H:i'}}",
"headers": {
"Authorization": "Basic TOKEN"
}
}
In the example above, the now variable is replaced with the current date and time, and different time manipulations are performed on it to generate different parts of the URL.
Syntax🔗
The syntax of the templating expressions is similar to that of the Django templating language. You can use variables, filters, and tags to manipulate and format the values.
Here's a brief overview of the available options:
Variables🔗
The following variables are available in the templates:
now: The current date and timetoday: The current date
Filters🔗
The following filters can be used to manipulate and format the values:
add_time
Adds a time delta to a date or datetime and returns the resulting date.
Syntax: {{ date_or_datetime|add_time:'1d0h0m0s' }}
Arguments:
date: The date or datetime to add time to1d0h0m0s: The time delta to add (1 day, 0 hours, 0 minutes, 0 seconds)
Info
Adding time to a date returns a datetime!
replace_time
Replaces parts of a date or datetime object with the specified values.
Syntax: {{ date_or_datetime|replace_time:'1d0h0m0s' }}
Arguments:
datetime: The date or datetime object to modify1d0h0m0s: The time values to replace (1 day, 0 hours, 0 minutes, 0 seconds)
Info
Replacing time in a date ({{ today|replace_time:'1h0m0s' }}) will return the source date without changes
Units of time🔗
y: yearsM: monthsd: daysh: hoursm: minutess: secondsus: microseconds
Timezone🔗
now and today are generated at the timezone in the server configuration. It is actually set to Europe/Zurich.
Warning
Everytime a datetime is updated using replace_time, we consider its timezone to be the same as the one on the server.
Date formatting🔗
You can use django builtin date filter to format the date or datetime to the required format.
Documentation is available here.
Example🔗
Here's an example of how to use the templating feature:
Suppose you want to retrieve time entries from a JSON API endpoint, and the URL for the endpoint needs to include time-related parameters based on the current date and time. You can use the templating feature to generate a dynamic URL for the API endpoint.