Changes in ow/views/user.py [6dc1846:5cf5787] in OpenWorkouts-current
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/views/user.py
r6dc1846 r5cf5787 166 166 """ 167 167 now = datetime.now(timezone.utc) 168 year = int(request.GET.get('year', now.year)) 169 month = int(request.GET.get('month', now.month)) 170 week = request.GET.get('week', None) 168 171 return { 169 'current_month': now.strftime('%Y-%m') 172 'workouts': context.workouts(year, month, week), 173 'current_month': '{year}-{month}'.format( 174 year=str(year), month=str(month).zfill(2)), 175 'current_week': week 170 176 } 171 177 … … 258 264 context=User, 259 265 permission='view', 260 name=' yearly')266 name='monthly') 261 267 def last_months_stats(context, request): 262 268 """ … … 280 286 'distance': int(round(stats[month]['distance'])), 281 287 'elevation': int(stats[month]['elevation']), 282 'workouts': stats[month]['workouts'] 288 'workouts': stats[month]['workouts'], 289 'url': request.resource_url( 290 context, 'profile', 291 query={'year': str(month[0]), 'month': str(month[1])}, 292 anchor='workouts') 283 293 } 284 294 json_stats.append(month_stats) … … 286 296 charset='utf-8', 287 297 body=json.dumps(json_stats)) 298 299 300 @view_config( 301 context=User, 302 permission='view', 303 name='weekly') 304 def last_weeks_stats(context, request): 305 """ 306 Return a json-encoded stream with statistics for the last 12-months, but 307 in a per-week basis 308 """ 309 stats = context.weekly_year_stats 310 # this sets which month is 2 times in the stats, once this year, once 311 # the previous year. We will show it a bit different in the UI (showing 312 # the year too to prevent confusion) 313 repeated_month = datetime.now(timezone.utc).date().month 314 json_stats = [] 315 for week in stats: 316 hms = timedelta_to_hms(stats[week]['time']) 317 name = month_name[week[1]][:3] 318 if week[1] == repeated_month: 319 name += ' ' + str(week[0]) 320 week_stats = { 321 'id': '-'.join( 322 [str(week[0]), str(week[1]).zfill(2), str(week[2])]), 323 'week': str(week[3]), # the number of week in the current month 324 'name': name, 325 'time': str(hms[0]).zfill(2), 326 'distance': int(round(stats[week]['distance'])), 327 'elevation': int(stats[week]['elevation']), 328 'workouts': stats[week]['workouts'], 329 'url': request.resource_url( 330 context, 'profile', 331 query={'year': str(week[0]), 332 'month': str(week[1]), 333 'week': str(week[2])}, 334 anchor='workouts') 335 } 336 json_stats.append(week_stats) 337 return Response(content_type='application/json', 338 charset='utf-8', 339 body=json.dumps(json_stats))
Note: See TracChangeset
for help on using the changeset viewer.