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


Ignore:
Timestamp:
Jan 25, 2019, 12:48:51 AM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
d0fc76b, ed7e9d7
Parents:
c6219ed (diff), 5bdfbfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge patches from darcs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/views/user.py

    rc6219ed r26220ba  
     1import json
    12from calendar import month_name
     3from datetime import datetime
    24
    35from pyramid.httpexceptions import HTTPFound
     
    1719from ..models.root import OpenWorkouts
    1820from ..views.renderers import OWFormRenderer
     21from ..utilities import timedelta_to_hms
    1922
    2023_ = TranslationStringFactory('OpenWorkouts')
     
    143146
    144147    return {
     148        'current_year': datetime.now().year,
     149        'current_day_name': datetime.now().strftime('%a'),
    145150        'month_name': month_name,
    146151        'viewing_year': viewing_year,
     
    223228        return HTTPFound(location=request.resource_url(context, 'profile'))
    224229    return {'form': OWFormRenderer(form)}
     230
     231
     232@view_config(
     233    context=User,
     234    permission='view',
     235    name='week')
     236def week_stats(context, request):
     237    stats = context.week_stats
     238    json_stats = []
     239    for day in stats:
     240        hms = timedelta_to_hms(stats[day]['time'])
     241        day_stats = {
     242            'name': day.strftime('%a'),
     243            'time': str(hms[0]).zfill(2),
     244            'distance': int(round(stats[day]['distance'])),
     245            'elevation': int(stats[day]['elevation']),
     246            'workouts': stats[day]['workouts']
     247        }
     248        json_stats.append(day_stats)
     249    return Response(content_type='application/json',
     250                    charset='utf-8',
     251                    body=json.dumps(json_stats))
Note: See TracChangeset for help on using the changeset viewer.