~oddbloke/readingthing/rt.dev

« back to all changes in this revision

Viewing changes to readingthing/list/views.py

  • Committer: Daniel Watkins
  • Date: 2010-01-01 02:44:16 UTC
  • Revision ID: daniel@daniel-watkins.co.uk-20100101024416-f4zsloaswdcbglhu
Just have to finish a book this year for it to count.

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
 
149
149
    today = date.today()
150
150
    year = today.year
151
 
    books_this_year = reading_list.filter(date_started__year=year,
152
 
                                          date_finished__year=year)
 
151
    books_this_year = reading_list.filter(date_finished__year=year)
153
152
    number_of_books_read = books_this_year.count()
154
153
 
155
154
    if number_of_books_read > 0:
156
155
        first_book = books_this_year.order_by('date_started')[0]
157
 
        start_date = first_book.date_started
 
156
        if first_book.date_started < date(today.year, 1, 1):
 
157
            start_date = date(today.year, 1, 1)
 
158
        else:
 
159
            start_date = first_book.start_date
158
160
 
159
161
        days = (today - start_date).days
160
162
        current_rate = float(days)/number_of_books_read