Skip to content

Commit 8458c74

Browse files
ajrbyersAndy Byers
authored andcommitted
Tweaked books for reporting
1 parent 4c4175e commit 8458c74

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

logic.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def book_metrics_by_month(books, date_parts):
114114
start = datetime.strptime(start_str, '%Y-%m-%d').date()
115115
end = datetime.strptime(end_str, '%Y-%m-%d').date()
116116

117+
current_year = date_parts.get('end_month_y')
118+
previous_year = str(int(current_year) - 1)
119+
117120
dates = [start]
118121

119122
while start < end:
@@ -138,9 +141,14 @@ def book_metrics_by_month(books, date_parts):
138141

139142
book_data['date_metrics'] = date_metrics_list
140143

144+
for year in [current_year, previous_year]:
145+
book_data[year] = book_metrics.filter(
146+
accessed__year=year,
147+
).count()
148+
141149
data.append(book_data)
142150

143-
return data, dates
151+
return data, dates, current_year, previous_year
144152

145153

146154
def get_chapter_contributor_items(book):

views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def book_metrics_by_month(request):
324324
}
325325
)
326326

327-
data, dates = logic.book_metrics_by_month(books, date_parts)
327+
data, dates, current_year, previous_year = logic.book_metrics_by_month(books, date_parts)
328328

329329
template = 'books/metrics_by_month.html'
330330
context = {

0 commit comments

Comments
 (0)