Changeset a3c3baa in OpenWorkouts-current


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)

Location:
ow
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ow/templates/profile.pt

    r40ee398 ra3c3baa  
    5151        <div class="workout-list">
    5252          <div class="total-workouts">
    53             <tal:w tal:replace="context.num_workouts"></tal:w>
    54             <tal:t i18n:translate="">workouts</tal:t>
     53            <span>
     54              <tal:w tal:replace="len(workouts)"></tal:w>
     55              <tal:t i18n:translate="">workouts</tal:t>
     56            </span>
     57            <span>
     58              <tal:hms tal:define="hms timedelta_to_hms(totals['time'])">
     59                <tal:h tal:content="str(hms[0]).zfill(2)"></tal:h>
     60                <tal:t i18n:translate="">hours</tal:t>,
     61                <tal:h tal:content="str(hms[1]).zfill(2)"></tal:h>
     62                <tal:t i18n:translate="">min.</tal:t>
     63              </tal:hms>
     64            </span>
     65            <span>
     66              <tal:w tal:replace="round(totals['distance'])"></tal:w>
     67              <tal:t i18n:translate="">km</tal:t>
     68            </span>
     69            <span>
     70              <tal:w tal:replace="round(totals['elevation'])"></tal:w>
     71              <tal:t i18n:translate="">m</tal:t>
     72            </span>
    5573          </div>
    5674
  • 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.