Changeset d1c4782 in OpenWorkouts-current for ow/utilities.py


Ignore:
Timestamp:
Jan 21, 2019, 10:43:20 AM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
be40b02
Parents:
ceae158
Message:

Show a capture of the workout map, as an image, in the dashboard:

  • Added a view to render the tracking map of a workout full screen
  • Added a small shell script that uses chrome to grabs a screenshot of the full screen map view of a workout, then uses imagemagick convert to crop/resize it and finally saves it in a given location
  • Added a static/maps directory to store maps captures
  • Added static/maps to the boring/ignore file
  • Added a tool in utilities.py to call the shell script that captures the screenshot of the map
  • Added a method to the Workout model, that returns the static path to the workout map capture (valid to use with request.static_url()). If there is no capture yet, call the tool to make one
  • Added code to dashboard.pt to show the capture of the map
  • Added a new parameter to te ow maps js code, allowing us to hide/show the zoom controls of the map when building a new one
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/utilities.py

    rceae158 rd1c4782  
    11import re
     2import os
     3import logging
     4import subprocess
    25from datetime import datetime
    36from decimal import Decimal
     
    710from xml.dom import minidom
    811from ZODB.blob import Blob
     12
     13log = logging.getLogger(__name__)
    914
    1015
     
    184189        open_blob.write(data)
    185190    return blob
     191
     192
     193def save_map_screenshot(workout):
     194    if workout.has_gpx:
     195        current_path = os.path.abspath(os.path.dirname(__file__))
     196        tool_path = os.path.join(current_path, '../bin/screenshot_map')
     197
     198        screenshots_path = os.path.join(
     199            current_path, 'static/maps', str(workout.owner.uid))
     200        if not os.path.exists(screenshots_path):
     201            os.makedirs(screenshots_path)
     202
     203        screenshot_path = os.path.join(
     204            screenshots_path, str(workout.workout_id))
     205        screenshot_path += '.png'
     206
     207        subprocess.run(
     208            [tool_path, str(workout.owner.uid), str(workout.workout_id),
     209             screenshot_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     210
     211        return True
     212
     213    return False
Note: See TracChangeset for help on using the changeset viewer.