diff --git a/fedireads/connectors/openlibrary.py b/fedireads/connectors/openlibrary.py index d34167bda..0261fa901 100644 --- a/fedireads/connectors/openlibrary.py +++ b/fedireads/connectors/openlibrary.py @@ -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() diff --git a/fedireads/view_actions.py b/fedireads/view_actions.py index f2945c7ec..279753eb5 100644 --- a/fedireads/view_actions.py +++ b/fedireads/view_actions.py @@ -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)