Changeset a3c3baa in OpenWorkouts-current for ow/views/user.py


Ignore:
Timestamp:
Feb 6, 2019, 1:25:07 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
978575d
Parents:
40ee398
Message:

Show the totals in the user profile, for the selected month/week
(number of workouts, time, distance and elevation)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/views/user.py

    r40ee398 ra3c3baa  
    11import json
    22from calendar import month_name
    3 from datetime import datetime, timezone
     3from datetime import datetime, timezone, timedelta
     4from decimal import Decimal
    45
    56from pyramid.httpexceptions import HTTPFound
     
    169170    month = int(request.GET.get('month', now.month))
    170171    week = request.GET.get('week', None)
     172    workouts = context.workouts(year, month, week)
     173    totals = {
     174        'distance': Decimal(0),
     175        'time': timedelta(0),
     176        'elevation': Decimal(0)
     177    }
     178
     179    for workout in workouts:
     180        totals['distance'] += getattr(workout, 'distance', Decimal(0))
     181        totals['time'] += getattr(workout, 'duration', timedelta(0))
     182        totals['elevation'] += getattr(workout, 'uphill', Decimal(0))
     183
    171184    return {
    172         'workouts': context.workouts(year, month, week),
     185        'workouts': workouts,
    173186        'current_month': '{year}-{month}'.format(
    174187            year=str(year), month=str(month).zfill(2)),
    175         'current_week': week
     188        'current_week': week,
     189        'totals': totals
    176190    }
    177191
Note: See TracChangeset for help on using the changeset viewer.