mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-27 02:20:31 +00:00
sort editions correctly for picking default
This commit is contained in:
parent
defd026ed0
commit
33327e2bb6
2 changed files with 13 additions and 3 deletions
|
@ -129,7 +129,7 @@ class Connector(AbstractConnector):
|
|||
response = requests.get(
|
||||
'%s/works/%s/editions.json' % (self.url, work.openlibrary_key))
|
||||
edition_data = response.json()
|
||||
for data in edition_data.get('entries', [])[:5]:
|
||||
for data in edition_data.get('entries', []):
|
||||
try:
|
||||
olkey = data['key'].split('/')[-1]
|
||||
except KeyError:
|
||||
|
@ -200,7 +200,17 @@ def set_default_edition(work):
|
|||
'paperback': 1,
|
||||
'mass market paperback': 2,
|
||||
}
|
||||
options = sorted(options, key=lambda e: format_prefs.get(e, 3))
|
||||
options = sorted(
|
||||
options,
|
||||
key=lambda e: format_prefs.get(str(e.physical_format).lower(), 3)
|
||||
)
|
||||
if options[0].physical_format in format_prefs:
|
||||
options = [e for e in options if \
|
||||
e.physical_format == options[0].physical_format]
|
||||
options = sorted(
|
||||
options,
|
||||
key=lambda e: -1 * e.published_date.year
|
||||
)
|
||||
options[0].default = True
|
||||
options[0].save()
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ def shelve(request):
|
|||
if request.POST.get('reshelve', True):
|
||||
try:
|
||||
current_shelf = models.Shelf.objects.get(
|
||||
shelf__user=request.user,
|
||||
user=request.user,
|
||||
edition=book
|
||||
)
|
||||
outgoing.handle_unshelve(request.user, book, current_shelf)
|
||||
|
|
Loading…
Reference in a new issue