Changes in ow/views/user.py [5cf5787:6dc1846] in OpenWorkouts-current


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/views/user.py

    r5cf5787 r6dc1846  
    166166    """
    167167    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)
    171     return {
    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
     168    return {
     169        'current_month': now.strftime('%Y-%m')
    176170    }
    177171
     
    264258    context=User,
    265259    permission='view',
    266     name='monthly')
     260    name='yearly')
    267261def last_months_stats(context, request):
    268262    """
     
    286280            'distance': int(round(stats[month]['distance'])),
    287281            'elevation': int(stats[month]['elevation']),
    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')
     282            'workouts': stats[month]['workouts']
    293283        }
    294284        json_stats.append(month_stats)
     
    296286                    charset='utf-8',
    297287                    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.