Using date-dependent params
API().get_entity_revisions has been introduced in the
viktor.api_v1 module, removing the need to use the
viktor.api module to obtain entity revisions.
Projects that make use of a database with prices are often invoiced with prices that may change over the years. If such prices are changed and the project is re-opened, the latest revision of the price-database is used by default. However, this could influence resulting data (e.g. a quotation) of an old project that the user would like to review. In such cases it is very helpful to select or specify a date at which the database settings were applicable.
Selecting a date can be implemented in different ways. Note that in case a
DateField is used to pick a date you should account for
possible UTC offsets. Assume a revision is created in Los Angeles at 17:00 local time (UTC-8), this will result in a
UTC time stamp at 1:00 the next day so the latter date should be selected. The user does not know this will
happen, so depending on the UTC zone of the user, the possible 1-day fluctuation should be taken into account.
- From the backend API, call the revisions of the 'settings' entity (e.g.
- Get the dates of the revisions, stored under 'created_date' property.
- Get the user-specified date.
- Since both dates are datetime objects, comparison can easily be done.
- Filter the revision that was applicable at the user-specified date.
The last step can vary depending on the way you would like to filter the revisions. For example if multiple revisions are created on the specified date, you can write an algorithm to select the correct revision of that day (e.g. the latest or first created). Make sure to notify the user whether the specified date is within the bounds of the possible revisions or not.