Changeset b3374f6 in OpenWorkouts-current for ow/models/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/models/workout.py

    rf713dbc rb3374f6  
    1414    create_blob,
    1515    mps_to_kmph,
    16     save_map_screenshot,
    1716    timedelta_to_hms
    1817)
     
    423422        return self.fit_file is not None
    424423
    425     def map_screenshot(self, request):
     424    @property
     425    def map_screenshot_name(self):
     426        return os.path.join(
     427            str(self.owner.uid), str(self.workout_id) + '.png')
     428
     429    @property
     430    def map_screenshot_path(self):
     431        current_path = os.path.abspath(os.path.dirname(__file__))
     432        return os.path.join(
     433            current_path, '../static/maps', self.map_screenshot_name)
     434
     435    @property
     436    def map_screenshot(self):
    426437        """
    427438        Return the static path to the screenshot image of the map for
     
    431442            return None
    432443
    433         screenshot_name = os.path.join(
    434             str(self.owner.uid), str(self.workout_id) + '.png')
    435         current_path = os.path.abspath(os.path.dirname(__file__))
    436         screenshot_path = os.path.join(
    437             current_path, '../static/maps', screenshot_name)
    438 
    439         if not os.path.exists(screenshot_path):
    440             # screenshot does not exist, generate it
    441             save_map_screenshot(self, request)
    442 
    443         static_path = os.path.join('static/maps', screenshot_name)
    444         return request.static_url('ow:' + static_path)
     444        if not os.path.exists(self.map_screenshot_path):
     445            return None
     446
     447        static_path = os.path.join('static/maps', self.map_screenshot_name)
     448        # return a string we can use with request.static_url
     449        return 'ow:' + static_path
Note: See TracChangeset for help on using the changeset viewer.