Changeset 3357e47 in OpenWorkouts-current for ow/views/user.py
- Timestamp:
- Feb 4, 2019, 12:38:29 PM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- 6993c72
- Parents:
- 1183d5a (diff), 5cf5787 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/views/user.py
r1183d5a r3357e47 168 168 year = int(request.GET.get('year', now.year)) 169 169 month = int(request.GET.get('month', now.month)) 170 week = request.GET.get('week', None) 170 171 return { 171 'workouts': context.workouts(year, month ),172 'workouts': context.workouts(year, month, week), 172 173 'current_month': '{year}-{month}'.format( 173 year=str(year), month=str(month).zfill(2)) 174 year=str(year), month=str(month).zfill(2)), 175 'current_week': week 174 176 } 175 177 … … 262 264 context=User, 263 265 permission='view', 264 name=' yearly')266 name='monthly') 265 267 def last_months_stats(context, request): 266 268 """ … … 294 296 charset='utf-8', 295 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.