mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +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(
|
response = requests.get(
|
||||||
'%s/works/%s/editions.json' % (self.url, work.openlibrary_key))
|
'%s/works/%s/editions.json' % (self.url, work.openlibrary_key))
|
||||||
edition_data = response.json()
|
edition_data = response.json()
|
||||||
for data in edition_data.get('entries', [])[:5]:
|
for data in edition_data.get('entries', []):
|
||||||
try:
|
try:
|
||||||
olkey = data['key'].split('/')[-1]
|
olkey = data['key'].split('/')[-1]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -200,7 +200,17 @@ def set_default_edition(work):
|
||||||
'paperback': 1,
|
'paperback': 1,
|
||||||
'mass market paperback': 2,
|
'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].default = True
|
||||||
options[0].save()
|
options[0].save()
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ def shelve(request):
|
||||||
if request.POST.get('reshelve', True):
|
if request.POST.get('reshelve', True):
|
||||||
try:
|
try:
|
||||||
current_shelf = models.Shelf.objects.get(
|
current_shelf = models.Shelf.objects.get(
|
||||||
shelf__user=request.user,
|
user=request.user,
|
||||||
edition=book
|
edition=book
|
||||||
)
|
)
|
||||||
outgoing.handle_unshelve(request.user, book, current_shelf)
|
outgoing.handle_unshelve(request.user, book, current_shelf)
|
||||||
|
|
Loading…
Reference in a new issue