Skip to content

Commit 5188e2a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent efafac0 commit 5188e2a

File tree

5 files changed

+129
-82
lines changed

5 files changed

+129
-82
lines changed

openlibrary/core/helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def datestr(
143143
now: datetime | None = None,
144144
lang: str | None = None,
145145
relative: bool = True,
146-
format: Literal['compact', 'long'] = 'long'
146+
format: Literal['compact', 'long'] = 'long',
147147
) -> str:
148148
"""Internationalized version of web.datestr."""
149149
if format == 'compact' and relative:
@@ -161,7 +161,9 @@ def datestr(
161161
return format_date(then, lang=lang)
162162

163163

164-
TimeDeltaUnit = namedtuple('TimeDeltaUnit', ['long_name', 'short_name', 'seconds_per_unit'])
164+
TimeDeltaUnit = namedtuple(
165+
'TimeDeltaUnit', ['long_name', 'short_name', 'seconds_per_unit']
166+
)
165167

166168
TIME_DELTA_UNITS = (
167169
TimeDeltaUnit('year', 'y', 3600 * 24 * 365),

openlibrary/i18n/messages.pot

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ msgid "Pending Imports"
8282
msgstr ""
8383

8484
#: BookByline.html FulltextSearchSuggestionItem.html SearchResultsWork.html
85-
#: account/notes.html account/observations.html
85+
#: account/activity_feed.html account/notes.html account/observations.html
8686
msgid "Unknown author"
8787
msgstr ""
8888

@@ -576,7 +576,7 @@ msgstr ""
576576
msgid "Failed to fetch carousel."
577577
msgstr ""
578578

579-
#: RawQueryCarousel.html
579+
#: RawQueryCarousel.html account/mybooks.html
580580
msgid "Retry?"
581581
msgstr ""
582582

@@ -1503,12 +1503,13 @@ msgstr ""
15031503
msgid "Notes"
15041504
msgstr ""
15051505

1506-
#: account/sidebar.html books/mybooks_breadcrumb_select.html
1507-
#: openlibrary/plugins/upstream/mybooks.py
1506+
#: account/mybooks.html account/sidebar.html
1507+
#: books/mybooks_breadcrumb_select.html openlibrary/plugins/upstream/mybooks.py
15081508
msgid "My Feed"
15091509
msgstr ""
15101510

1511-
#: account/mybooks.html account/readinglog_shelf_name.html account/sidebar.html
1511+
#: account/activity_feed.html account/mybooks.html
1512+
#: account/readinglog_shelf_name.html account/sidebar.html
15121513
#: my_books/dropdown_content.html my_books/primary_action.html
15131514
#: openlibrary/plugins/upstream/mybooks.py search/sort_options.html
15141515
msgid "Already Read"
@@ -2300,12 +2301,14 @@ msgstr ""
23002301
msgid "Earliest trending data is from October 2017"
23012302
msgstr ""
23022303

2303-
#: account/mybooks.html account/sidebar.html my_books/dropdown_content.html
2304-
#: my_books/primary_action.html search/sort_options.html trending.html
2304+
#: account/activity_feed.html account/mybooks.html account/sidebar.html
2305+
#: my_books/dropdown_content.html my_books/primary_action.html
2306+
#: search/sort_options.html trending.html
23052307
msgid "Want to Read"
23062308
msgstr ""
23072309

2308-
#: account/mybooks.html account/readinglog_shelf_name.html account/sidebar.html
2310+
#: account/activity_feed.html account/mybooks.html
2311+
#: account/readinglog_shelf_name.html account/sidebar.html
23092312
#: my_books/dropdown_content.html my_books/primary_action.html
23102313
#: search/sort_options.html trending.html
23112314
msgid "Currently Reading"
@@ -2478,6 +2481,22 @@ msgid ""
24782481
"information form</a>."
24792482
msgstr ""
24802483

2484+
#: account/activity_feed.html lists/list_follow.html
2485+
msgid "Avatar of the owner of the list"
2486+
msgstr ""
2487+
2488+
#: account/activity_feed.html
2489+
msgid ""
2490+
"Here's the latest activity around the library. Follow other readers to "
2491+
"personalize your feed."
2492+
msgstr ""
2493+
2494+
#: account/activity_feed.html
2495+
msgid ""
2496+
"None of the people that you follow have logged books. When they do, "
2497+
"you'll see it here."
2498+
msgstr ""
2499+
24812500
#: account/create.html
24822501
msgid "Username may only contain numbers, letters, - or _"
24832502
msgstr ""
@@ -2754,6 +2773,14 @@ msgstr ""
27542773
msgid "My Loans"
27552774
msgstr ""
27562775

2776+
#: account/mybooks.html
2777+
msgid "Loading activity feed"
2778+
msgstr ""
2779+
2780+
#: account/mybooks.html
2781+
msgid "Failed to fetch activity feed."
2782+
msgstr ""
2783+
27572784
#: account/mybooks.html type/user/view.html
27582785
msgid "This reader has chosen to make their Reading Log private."
27592786
msgstr ""
@@ -2763,6 +2790,10 @@ msgstr ""
27632790
msgid "%(year_span)s reading goal"
27642791
msgstr ""
27652792

2793+
#: account/mybooks.html
2794+
msgid "Activity Feed"
2795+
msgstr ""
2796+
27662797
#: account/mybooks.html
27672798
msgid "View All Lists"
27682799
msgstr ""
@@ -6334,10 +6365,6 @@ msgstr ""
63346365
msgid "Cover of book"
63356366
msgstr ""
63366367

6337-
#: lists/list_follow.html
6338-
msgid "Avatar of the owner of the list"
6339-
msgstr ""
6340-
63416368
#: lists/list_follow.html lists/widget.html my_books/dropdown_content.html
63426369
msgid "You"
63436370
msgstr ""

openlibrary/plugins/openlibrary/partials.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,18 @@ def generate(self) -> dict:
355355
return {"partials": str(macro)}
356356

357357

358-
359358
class ActivityFeedPartial(PartialDataHandler):
360359
"""Handler for "My Books" page activity feeds"""
360+
361361
def __init__(self):
362362
self.i = web.input(username=None)
363363

364364
def generate(self) -> dict:
365365
feed, follows_others = ActivityFeed.get_activity_feed(self.i.username)
366366
feed_url = f'/people/{self.i.username}/books/feed'
367-
template_result = render_template('account/activity_feed', feed, feed_url, follows_others)
367+
template_result = render_template(
368+
'account/activity_feed', feed, feed_url, follows_others
369+
)
368370
return {"partials": str(template_result)}
369371

370372

openlibrary/plugins/upstream/mybooks.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from infogami.utils.view import public, render, safeint
1212
from openlibrary import accounts
1313
from openlibrary.accounts.model import (
14-
OpenLibraryAccount, # noqa: F401 side effects may be needed
14+
OpenLibraryAccount,
1515
)
1616
from openlibrary.core.booknotes import Booknotes
1717
from openlibrary.core.bookshelves import Bookshelves
@@ -26,7 +26,7 @@
2626
from openlibrary.core.observations import Observations, convert_observation_ids
2727
from openlibrary.i18n import gettext as _
2828
from openlibrary.plugins.openlibrary.home import caching_prethread
29-
from openlibrary.utils import extract_numeric_id_from_olid, dateutil
29+
from openlibrary.utils import dateutil, extract_numeric_id_from_olid
3030
from openlibrary.utils.dateutil import current_year
3131

3232
if TYPE_CHECKING:
@@ -677,20 +677,26 @@ def get_pub_sub_feed(cls, username):
677677
@classmethod
678678
def get_cached_pub_sub_feed(cls, username):
679679
five_minutes = 5 * dateutil.MINUTE_SECS
680-
mc = memcache_memoize(cls.get_pub_sub_feed, key_prefix="mybooks.pubsub.feed", timeout=five_minutes, prethread=caching_prethread())
680+
mc = memcache_memoize(
681+
cls.get_pub_sub_feed,
682+
key_prefix="mybooks.pubsub.feed",
683+
timeout=five_minutes,
684+
prethread=caching_prethread(),
685+
)
681686
results = mc(username)
682687

683688
for r in results:
684-
if isinstance(r['created'], str): # `datetime` objects are stored in cache as strings
689+
if isinstance(
690+
r['created'], str
691+
): # `datetime` objects are stored in cache as strings
685692
# Update `created` to datetime, which is the type expected by `datestr` (called in card template)
686693
r['created'] = datetime.fromisoformat(r['created'])
687694
return results
688695

689696
@classmethod
690697
def get_trending_feed(cls, username):
691698
def has_public_reading_log(_username):
692-
acct = OpenLibraryAccount.get_by_username(_username)
693-
if acct:
699+
if acct := OpenLibraryAccount.get_by_username(_username):
694700
user = acct.get_user()
695701
return user and user.preferences().get('public_readlog', 'no') == 'yes'
696702
return False
@@ -700,7 +706,11 @@ def has_public_reading_log(_username):
700706

701707
feed = []
702708
for idx, item in enumerate(logged_books):
703-
if item['work'] and item['username'] != username and has_public_reading_log(item['username']):
709+
if (
710+
item['work']
711+
and item['username'] != username
712+
and has_public_reading_log(item['username'])
713+
):
704714
feed.append(item)
705715
if len(feed) > 2:
706716
break
@@ -710,16 +720,22 @@ def has_public_reading_log(_username):
710720
@classmethod
711721
def get_cached_trending_feed(cls, username):
712722
five_minutes = 5 * dateutil.MINUTE_SECS
713-
mc = memcache_memoize(cls.get_trending_feed, key_prefix="mybooks.trending.feed", timeout=five_minutes, prethread=caching_prethread())
723+
mc = memcache_memoize(
724+
cls.get_trending_feed,
725+
key_prefix="mybooks.trending.feed",
726+
timeout=five_minutes,
727+
prethread=caching_prethread(),
728+
)
714729
results = mc(username)
715730

716731
for r in results:
717-
if isinstance(r['created'], str): # `datetime` objects are stored in cache as strings
732+
if isinstance(
733+
r['created'], str
734+
): # `datetime` objects are stored in cache as strings
718735
r['created'] = datetime.fromisoformat(r['created'])
719736
return results
720737

721738

722739
@public
723740
def get_activity_feed(username):
724741
return ActivityFeed.get_activity_feed(username)
725-
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
11
.activity-feed {
2-
display: flex;
3-
padding: 8px 0;
2+
display: flex;
3+
padding: 8px 0;
44
}
55

66
.activity-feed-card {
7-
width: 215px;
8-
height: 150px;
9-
border: 1px solid fade(@black, 25%);
10-
margin-right: 24px;
11-
border-radius: 4px;
12-
box-shadow: 2px 2px 4px fade(@black, 15%);
7+
width: 215px;
8+
height: 150px;
9+
border: 1px solid fade(@black, 25%);
10+
margin-right: 24px;
11+
border-radius: 4px;
12+
box-shadow: 2px 2px 4px fade(@black, 15%);
1313
}
1414

1515
.activity-feed-card__body {
16-
background-color: @beige;
16+
background-color: @beige;
17+
display: flex;
18+
height: 105px;
19+
padding: 10px;
20+
.activity-feed-card__cover-image img {
21+
width: 55px;
22+
height: 85px;
23+
box-shadow: 4px 4px 4px 0 fade(@black, 25%);
24+
margin-right: 10px;
25+
}
26+
.activity-feed-card__book-details {
1727
display: flex;
18-
height: 105px;
19-
padding: 10px;
20-
.activity-feed-card__cover-image img {
21-
width: 55px;
22-
height: 85px;
23-
box-shadow: 4px 4px 4px 0 fade(@black, 25%);
24-
margin-right: 10px;
28+
flex-direction: column;
29+
.activity-feed-card__book-title {
30+
font-size: 14px;
31+
font-weight: 700;
32+
}
33+
.activity-feed-card__author-name,
34+
.activity-feed-card__book-subtitle {
35+
font-size: 12px;
36+
margin-top: 5px;
2537
}
26-
.activity-feed-card__book-details {
27-
display: flex;
28-
flex-direction: column;
29-
.activity-feed-card__book-title {
30-
font-size: 14px;
31-
font-weight: 700;
32-
}
33-
.activity-feed-card__author-name,
34-
.activity-feed-card__book-subtitle {
35-
font-size: 12px;
36-
margin-top: 5px;
37-
}
38-
.activity-feed-card__book-subtitle {
39-
font-style: italic;
40-
}
38+
.activity-feed-card__book-subtitle {
39+
font-style: italic;
4140
}
41+
}
4242
}
4343

4444
.activity-feed-card__footer {
45-
background: #f4f4f4;
46-
border-radius: 0 0 4px 4px;
47-
box-shadow: 0 0 4px fade(@black, 25%);
48-
display: flex;
49-
padding: 8px;
50-
height: 45px;
51-
font-size: 12px;
45+
background: #f4f4f4;
46+
border-radius: 0 0 4px 4px;
47+
box-shadow: 0 0 4px fade(@black, 25%);
48+
display: flex;
49+
padding: 8px;
50+
height: 45px;
51+
font-size: 12px;
5252

53-
.activity-feed-card__footer-copy {
54-
margin-right: 9px;
55-
}
56-
.cta-btn {
57-
font-size: 12px;
58-
width: unset;
59-
height: 24px;
60-
padding: 3px 10px;
61-
}
62-
.shelf-link {
63-
text-decoration: none;
64-
}
65-
.activity-feed-card__avatar img {
66-
border-radius: 8px;
67-
width: 30px;
68-
height: 30px;
69-
border: 2px solid @white;
70-
}
53+
.activity-feed-card__footer-copy {
54+
margin-right: 9px;
55+
}
56+
.cta-btn {
57+
font-size: 12px;
58+
width: unset;
59+
height: 24px;
60+
padding: 3px 10px;
61+
}
62+
.shelf-link {
63+
text-decoration: none;
64+
}
65+
.activity-feed-card__avatar img {
66+
border-radius: 8px;
67+
width: 30px;
68+
height: 30px;
69+
border: 2px solid @white;
70+
}
7171
}

0 commit comments

Comments
 (0)