Skip to content

Commit b65fc44

Browse files
RedJade26cdrini
andauthored
Add option to filter reading stats by year read (#10679)
Co-authored-by: Drini Cami <[email protected]>
1 parent 665a3b5 commit b65fc44

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

openlibrary/plugins/upstream/mybooks.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ def GET(self, username):
157157

158158

159159
class readinglog_stats(delegate.page):
160-
path = "/people/([^/]+)/books/(want-to-read|currently-reading|already-read)/stats"
160+
path = "/people/([^/]+)/books/(want-to-read|currently-reading|already-read)(/year/\\d{4})?/stats"
161161

162-
def GET(self, username, key='want-to-read'):
162+
def GET(self, username, key='want-to-read', year=None):
163163
user = web.ctx.site.get('/people/%s' % username)
164164
if not user:
165165
return render.notfound("User %s" % username, create=False)
@@ -168,8 +168,13 @@ def GET(self, username, key='want-to-read'):
168168
if not cur_user or cur_user.key.split('/')[-1] != username:
169169
return render.permission_denied(web.ctx.path, 'Permission Denied')
170170

171+
yearly_reads = BookshelvesEvents.get_user_yearly_read_counts(username)
172+
if year:
173+
# eg '/year/2025'; skip the '/year/'
174+
year = int(year.split('/')[-1])
175+
171176
readlog = ReadingLog(user=user)
172-
works = readlog.get_works(key, page=1, limit=2000).docs
177+
works = readlog.get_works(key, page=1, limit=2000, year=year).docs
173178
works_json = [
174179
{
175180
# Fallback to key if it is a redirect
@@ -203,6 +208,8 @@ def GET(self, username, key='want-to-read'):
203208
web.ctx.path.rsplit('/', 1)[0],
204209
key,
205210
lang=web.ctx.lang,
211+
year=year,
212+
yearly_reads=yearly_reads,
206213
)
207214

208215

openlibrary/templates/account/readinglog_stats.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$def with (works_json, authors_json, works_count, owner_key, owner_name, shelf_path, shelf_key, lang='en')
1+
$def with (works_json, authors_json, works_count, owner_key, owner_name, shelf_path, shelf_key, year,yearly_reads, lang='en')
22

33
$ reading_log_stats_config = {
44
$ 'works': works_json,
@@ -104,6 +104,19 @@
104104
&raquo;
105105
</div>
106106
<h1>$_('My %(shelf_name)s Stats', shelf_name=shelf_name)</h1>
107+
$if shelf_key == 'already-read' and yearly_reads:
108+
<div class="breadcrumb-wrapper">
109+
<div class="sansserif grey account-settings-menu navigation-breadcrumbs">
110+
$ all_url = owner_key + '/books/already-read/stats'
111+
$ year_url = owner_key + '/books/already-read/year/%d/stats'
112+
$if year:
113+
$:render_template("books/year_breadcrumb_select", yearly_reads, all_url, year_url, selected= str(year))
114+
$else:
115+
116+
$:render_template("books/year_breadcrumb_select", yearly_reads, all_url, year_url )
117+
118+
</div>
119+
</div>
107120

108121
<p>$:_('Displaying stats about <strong>%(works_count)d</strong> books. Note all charts show only the top 20 bars. Note reading log stats are private.', works_count=works_count)</p>
109122
</div>

0 commit comments

Comments
 (0)