From a96d027cf3699faaff3cfbd961183cf1d6bf5200 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 22 Sep 2021 16:16:53 -0700 Subject: [PATCH] Easier to read first-item-or-none list logic --- bookwyrm/views/reading.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py index 585d77db..99e95ddb 100644 --- a/bookwyrm/views/reading.py +++ b/bookwyrm/views/reading.py @@ -56,14 +56,12 @@ class ReadingStatus(View): ) # gets the first shelf that indicates a reading status, or None - current_status_shelfbook = next( - iter( - s - for s in book.current_shelves - if s.shelf.identifier in models.Shelf.READ_STATUS_IDENTIFIERS - ), - None, - ) + shelves = [ + s + for s in book.current_shelves + if s.shelf.identifier in models.Shelf.READ_STATUS_IDENTIFIERS + ] + current_status_shelfbook = shelves[0] if shelves else None # checking the referer prevents redirecting back to the modal page referer = request.headers.get("Referer", "/")