Changeset 1d2acd4 in OpenWorkouts-current for ow/models/user.py


Ignore:
Timestamp:
Feb 4, 2019, 12:30:27 PM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
63df989
Parents:
9ab0fe3
Message:

The workouts() method of the User model accepts a new parameter, week,

which lets us filter workouts for a given week number, relative to a year

(for example, year 2018, week 44)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/models/user.py

    r9ab0fe3 r1d2acd4  
    7777        reindex_object(catalog, workout)
    7878
    79     def workouts(self, year=None, month=None):
     79    def workouts(self, year=None, month=None, week=None):
    8080        """
    8181        Return this user workouts, sorted by date, from newer to older
     
    8484        if year:
    8585            workouts = [w for w in workouts if w.start.year == year]
    86         if month:
    87             workouts = [w for w in workouts if w.start.month == month]
     86            if month:
     87                workouts = [w for w in workouts if w.start.month == month]
     88            if week:
     89                week = int(week)
     90                workouts = [
     91                    w for w in workouts if w.start.isocalendar()[1] == week]
    8892        workouts = sorted(workouts, key=attrgetter('start'))
    8993        workouts.reverse()
Note: See TracChangeset for help on using the changeset viewer.