Skip to content

Commit f96ef14

Browse files
authored
Merge pull request #10743 from cdrini/refactor/rm-dead-methods
Remove/move some dead methods
2 parents 2fe532a + 6ddad37 commit f96ef14

File tree

2 files changed

+27
-61
lines changed

2 files changed

+27
-61
lines changed

openlibrary/plugins/openlibrary/code.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
batch_import,
2222
)
2323
from openlibrary.i18n import gettext as _
24-
from openlibrary.plugins.upstream.utils import setup_requests
24+
from openlibrary.plugins.upstream.utils import get_coverstore_public_url, setup_requests
2525

2626
# make sure infogami.config.features is set
2727
if not hasattr(infogami.config, 'features'):
@@ -42,7 +42,6 @@
4242
from openlibrary.core.lending import get_availability
4343
from openlibrary.core.models import Edition
4444
from openlibrary.plugins.openlibrary import processors
45-
from openlibrary.plugins.openlibrary.home import format_work_data
4645
from openlibrary.plugins.openlibrary.stats import increment_error_count
4746
from openlibrary.utils.isbn import canonical, isbn_10_to_isbn_13, isbn_13_to_isbn_10
4847

@@ -276,6 +275,31 @@ def GET(self, key: str): # type: ignore[override]
276275
)
277276

278277

278+
def format_work_data(work):
279+
d = dict(work)
280+
281+
key = work.get('key', '')
282+
# New solr stores the key as /works/OLxxxW
283+
if not key.startswith("/works/"):
284+
key = "/works/" + key
285+
286+
d['url'] = key
287+
d['title'] = work.get('title', '')
288+
289+
if 'author_key' in work and 'author_name' in work:
290+
d['authors'] = [
291+
{"key": key, "name": name}
292+
for key, name in zip(work['author_key'], work['author_name'])
293+
]
294+
295+
if 'cover_edition_key' in work:
296+
coverstore_url = get_coverstore_public_url()
297+
d['cover_url'] = f"{coverstore_url}/b/olid/{work['cover_edition_key']}-M.jpg"
298+
299+
d['read_url'] = "//archive.org/stream/" + work['ia'][0]
300+
return d
301+
302+
279303
class addauthor(delegate.page):
280304
path = '/addauthor'
281305

openlibrary/plugins/openlibrary/home.py

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from infogami.utils.view import public, render_template
1212
from openlibrary.core import admin, cache, ia, lending
1313
from openlibrary.i18n import gettext as _
14-
from openlibrary.plugins.upstream.utils import get_blog_feeds, get_coverstore_public_url
14+
from openlibrary.plugins.upstream.utils import get_blog_feeds
1515
from openlibrary.plugins.worksearch import search, subjects
1616
from openlibrary.utils import dateutil
1717

@@ -201,64 +201,6 @@ def generic_carousel(
201201
return storify(books) if books else books
202202

203203

204-
def format_list_editions(key):
205-
"""Formats the editions of a list suitable for display in carousel."""
206-
if 'env' not in web.ctx:
207-
delegate.fakeload()
208-
209-
seed_list = web.ctx.site.get(key)
210-
if not seed_list:
211-
return []
212-
213-
editions = {}
214-
for seed in seed_list.seeds:
215-
if not isinstance(seed, str):
216-
if seed.type.key == "/type/edition":
217-
editions[seed.key] = seed
218-
else:
219-
try:
220-
e = pick_best_edition(seed)
221-
except StopIteration:
222-
continue
223-
editions[e.key] = e
224-
return [format_book_data(e) for e in editions.values()]
225-
226-
227-
# cache the results of format_list_editions in memcache for 5 minutes
228-
format_list_editions = cache.memcache_memoize(
229-
format_list_editions, "home.format_list_editions", timeout=5 * 60
230-
)
231-
232-
233-
def pick_best_edition(work):
234-
return next(e for e in work.editions if e.ocaid)
235-
236-
237-
def format_work_data(work):
238-
d = dict(work)
239-
240-
key = work.get('key', '')
241-
# New solr stores the key as /works/OLxxxW
242-
if not key.startswith("/works/"):
243-
key = "/works/" + key
244-
245-
d['url'] = key
246-
d['title'] = work.get('title', '')
247-
248-
if 'author_key' in work and 'author_name' in work:
249-
d['authors'] = [
250-
{"key": key, "name": name}
251-
for key, name in zip(work['author_key'], work['author_name'])
252-
]
253-
254-
if 'cover_edition_key' in work:
255-
coverstore_url = get_coverstore_public_url()
256-
d['cover_url'] = f"{coverstore_url}/b/olid/{work['cover_edition_key']}-M.jpg"
257-
258-
d['read_url'] = "//archive.org/stream/" + work['ia'][0]
259-
return d
260-
261-
262204
def format_book_data(book, fetch_availability=True):
263205
d = web.storage()
264206
d.key = book.get('key')

0 commit comments

Comments
 (0)