Changes in ow/views/user.py [6dc1846:5bdfbfb] in OpenWorkouts-current
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/views/user.py
r6dc1846 r5bdfbfb 1 1 import json 2 2 from calendar import month_name 3 from datetime import datetime , timezone3 from datetime import datetime 4 4 5 5 from pyramid.httpexceptions import HTTPFound … … 146 146 147 147 return { 148 'current_year': datetime.now( timezone.utc).year,149 'current_day_name': datetime.now( timezone.utc).strftime('%a'),148 'current_year': datetime.now().year, 149 'current_day_name': datetime.now().strftime('%a'), 150 150 'month_name': month_name, 151 151 'viewing_year': viewing_year, … … 165 165 basic info, stats, etc 166 166 """ 167 now = datetime.now(timezone.utc) 168 return { 169 'current_month': now.strftime('%Y-%m') 170 } 167 return {} 171 168 172 169 … … 253 250 charset='utf-8', 254 251 body=json.dumps(json_stats)) 255 256 257 @view_config(258 context=User,259 permission='view',260 name='yearly')261 def last_months_stats(context, request):262 """263 Return a json-encoded stream with statistics for the last 12 months264 """265 stats = context.yearly_stats266 # this sets which month is 2 times in the stats, once this year, once267 # the previous year. We will show it a bit different in the UI (showing268 # the year too to prevent confusion)269 repeated_month = datetime.now(timezone.utc).date().month270 json_stats = []271 for month in stats:272 hms = timedelta_to_hms(stats[month]['time'])273 name = month_name[month[1]][:3]274 if month[1] == repeated_month:275 name += ' ' + str(month[0])276 month_stats = {277 'id': str(month[0]) + '-' + str(month[1]).zfill(2),278 'name': name,279 'time': str(hms[0]).zfill(2),280 'distance': int(round(stats[month]['distance'])),281 'elevation': int(stats[month]['elevation']),282 'workouts': stats[month]['workouts']283 }284 json_stats.append(month_stats)285 return Response(content_type='application/json',286 charset='utf-8',287 body=json.dumps(json_stats))
Note: See TracChangeset
for help on using the changeset viewer.