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, tile_requester, layer, 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.

  • badges (list[Badge]) – Badges to attach to the track.

  • tagged_people (list[User]) – List of people to tag.

  • tags (list[str]) – List of text tags for the track.

  • transformers (list[Transformer]) – List of Transformer to apply.

  • gpx_data (bytes) – Actual GPX data (uncompressed, straight from the source).

Return type:

Track

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[...] and image-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).

Parameters:
  • request (Request) – The request.

  • track (Track) – The track.

fietsboek.actions.extract_climbs(dbsession, track, tile_requester, layer, overpass_api)

(Re-)extracts the climbs from the given track.

If the track already has climbs assigned, they will be deleted.

Parameters:
  • dbsession (Session) – The database session.

  • track (Track) – The track for which to extract climbs.

  • tile_requester (TileRequester) – The tile requester to use to render preview images.

  • layer (TileLayerConfig) – The layer to use for preview images.

  • overpass_api (OverpassApi | None) – The overpass API to use for naming the climbs. If None, climbs will not be named.

  • find_names – Whether names should be searched or not.

fietsboek.actions.extract_climbs_background(request, track_id)

Re-extracts the climbs of the given track in the background.

This spawns a new thread that calls extract_climbs() in a new thread.

Parameters:
  • request (Request) – The request.

  • track_id (int) – The track’s id.

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.

Parameters:
  • request (Request) – The request.

  • user (User) – The user who to generate a verification token for.