fietsboek.actions module¶
High-level actions.
This module implements the basic logic for high level intents such as “add a track”, “delete a track”, … It combines the low-level APIs of the ORM and the data manager, and provides functions that can be used by the views, the API and the test functions.
- fietsboek.actions.add_track(dbsession, data_manager, owner, title, date, visibility, track_type, description, badges, tagged_people, tags, transformers, gpx_data)¶
Adds a track to the database.
Note that this function does not do any authorization checking, and as such, expects the caller to ensure that everything is in order.
Most of the parameters correspond to the attributes of
Track
objects.- Parameters:
dbsession (
Session
) – The database session.data_manager (
DataManager
) – The data manager.owner (
User
) – The owner of the track.title (
str
) – Title of the track.date (
datetime
) – Date of the track, should be timezone-aware.visibility (
Visibility
) – Track visibility.track_type (
TrackType
) – Type of the track.description (
str
) – Track description.transformers (
list
[Transformer
]) – List ofTransformer
to apply.gpx_data (
bytes
) – Actual GPX data (uncompressed, straight from the source).
- Return type:
- Returns:
The track object that has been inserted into the database. Useful for its
id
attribute.
- fietsboek.actions.edit_images(request, track, *, manager=None)¶
Edit the images according to the given request.
This deletes and adds images and image descriptions as needed, based on the
image[...]
andimage-description[...]
fields.- Parameters:
request (
Request
) – The request.track (
Track
) – The track to edit.manager (
Optional
[TrackDataDir
]) – The track’s data manager. If not given, it will automatically be opened from the request.
- fietsboek.actions.execute_transformers(request, track)¶
Execute the transformers for the given track.
Note that this function “short circuits” if the saved transformer settings already match the settings given in the request.
This function saves the modified data, but does also return it in case you need to do further processing (unless no transformations have taken place).
- fietsboek.actions.send_verification_token(request, user)¶
Creates a verification token and sends it to the user.
If no verification token exists yet, a fresh one is created.
If a token already exists, a fresh one is still created. The old token stays valid until its expiry date.
Note that this function does not provide the user with feedback other than the email. You may want to show a flash message or similar to show that something has happened.