Changeset b3374f6 in OpenWorkouts-current for ow/views/workout.py


Ignore:
Timestamp:
Feb 12, 2019, 5:55:33 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
c999b73e
Parents:
f713dbc
Message:

(#52) - Make map screenshot generation async and non-blocker of the dashboard
and user profile pages:

  • workout.map_screenshot is a property again, returns a string with the static path (suitable for use with request.static_url()) for the map screenshot file if exists, none otherwise
  • added a couple of helpers to build the proper screenshot name and full path on the filesystem
  • added a view to generate the map if needed, returning the full static url to the screenshot file in a json-encoded stream
  • added a new js ow tool that looks for workouts that still don't have a map screenshot, calling the view to generate that screenshot and updating the map screenshot when the file is ready
  • modified the dashboard and user profile templates, so a dummy/placeholder image is shown when no map screenshot is yet ready, plus setup and calls for the js tool that generates the maps.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/views/workout.py

    rf713dbc rb3374f6  
    11from decimal import Decimal
    22from datetime import datetime, timedelta, time, timezone
     3import json
    34
    45import gpxpy
     
    1718from ..models.workout import Workout
    1819from ..models.user import User
    19 from ..utilities import slugify
     20from ..utilities import slugify, save_map_screenshot
    2021from ..catalog import get_catalog, reindex_object, remove_from_catalog
    2122
     
    255256                               'elevation': center_point.elevation}
    256257    return {'start_point': start_point}
     258
     259
     260@view_config(
     261    context=Workout,
     262    permission='edit',
     263    name='map-shot')
     264def workout_map_shot(context, request):
     265    """
     266    Ask for the screenshot of a map, creating one if it does not exist.
     267    A json object is returned, containing the info for the needed screenshot
     268    """
     269    if context.map_screenshot is None:
     270        save_map_screenshot(context, request)
     271
     272    info = {'url': request.static_url(context.map_screenshot)}
     273    return Response(content_type='application/json',
     274                    charset='utf-8',
     275                    body=json.dumps(info))
Note: See TracChangeset for help on using the changeset viewer.