From ea303fb285766e30032a67f8c7bb196d8ef7b0e0 Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Mon, 20 Sep 2021 16:44:59 -0700
Subject: [PATCH] Updating string format synatx part 3
---
bookwyrm/activitystreams.py | 5 ++---
bookwyrm/models/status.py | 10 ++++++++--
bookwyrm/preview_images.py | 4 +++-
bookwyrm/settings.py | 4 +---
bookwyrm/urls.py | 4 ++--
bookwyrm/views/books.py | 12 ++++++------
6 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py
index c2b3da5e..5e0969e5 100644
--- a/bookwyrm/activitystreams.py
+++ b/bookwyrm/activitystreams.py
@@ -20,9 +20,8 @@ class ActivityStream(RedisStore):
def unread_id(self, user):
"""the redis key for this user's unread count for this stream"""
- return "{}-unread".format(
- self.stream_id(user)
- ) # pylint: disable=consider-using-f-string
+ stream_id = self.stream_id(user)
+ return f"{stream_id}-unread"
def get_rank(self, obj): # pylint: disable=no-self-use
"""statuses are sorted by date published"""
diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py
index e3a3d387..0a51f6a3 100644
--- a/bookwyrm/models/status.py
+++ b/bookwyrm/models/status.py
@@ -277,7 +277,10 @@ class Comment(BookStatus):
@property
def pure_content(self):
"""indicate the book in question for mastodon (or w/e) users"""
- return f'{self.content}(comment on "{self.book.title}")
'
+ return (
+ f'{self.content}(comment on '
+ '"{self.book.title}")
'
+ )
activity_serializer = activitypub.Comment
@@ -302,7 +305,10 @@ class Quotation(BookStatus):
"""indicate the book in question for mastodon (or w/e) users"""
quote = re.sub(r"^", '
"', self.quote)
quote = re.sub(r"
$", '"
', quote)
- return f'{quote} -- "{self.book.title}"
{self.content}'
+ return (
+ f'{quote} -- '
+ '"{self.book.title}"
{self.content}'
+ )
activity_serializer = activitypub.Quotation
diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py
index 55af3532..17377f95 100644
--- a/bookwyrm/preview_images.py
+++ b/bookwyrm/preview_images.py
@@ -220,6 +220,7 @@ def generate_default_inner_img():
# pylint: disable=too-many-locals
+# pylint: disable=too-many-statements
def generate_preview_image(
texts=None, picture=None, rating=None, show_instance_layer=True
):
@@ -237,7 +238,8 @@ def generate_preview_image(
# Color
if BG_COLOR in ["use_dominant_color_light", "use_dominant_color_dark"]:
- image_bg_color = "rgb(%s, %s, %s)" % dominant_color
+ red, green, blue = dominant_color
+ image_bg_color = f"rgb({red}, {green}, {blue})"
# Adjust color
image_bg_color_rgb = [x / 255.0 for x in ImageColor.getrgb(image_bg_color)]
diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py
index 1a05120b..f2c329f0 100644
--- a/bookwyrm/settings.py
+++ b/bookwyrm/settings.py
@@ -23,9 +23,7 @@ EMAIL_HOST_USER = env("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True)
EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", False)
-DEFAULT_FROM_EMAIL = "admin@{:s}".format(
- env("DOMAIN")
-) # pylint: disable=consider-using-f-string
+DEFAULT_FROM_EMAIL = f"admin@{DOMAIN}"
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py
index 2924bd97..7cf99af3 100644
--- a/bookwyrm/urls.py
+++ b/bookwyrm/urls.py
@@ -20,8 +20,8 @@ status_types = [
"generatednote",
]
-status_types_string = "|".join(status_types)
-STATUS_PATH = rf"{USER_PATH}/({status_types_string})/(?P\d+)"
+STATUS_TYPES_STRING = "|".join(status_types)
+STATUS_PATH = rf"{USER_PATH}/({STATUS_TYPES_STRING})/(?P\d+)"
BOOK_PATH = r"^book/(?P\d+)"
diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py
index c2525295..a31a99e7 100644
--- a/bookwyrm/views/books.py
+++ b/bookwyrm/views/books.py
@@ -174,7 +174,7 @@ class EditBook(View):
# check if this is an edition of an existing work
author_text = book.author_text if book else add_author
data["book_matches"] = connector_manager.local_search(
- "%s %s" % (form.cleaned_data.get("title"), author_text),
+ f'{form.cleaned_data.get("title")} {author_text}',
min_confidence=0.5,
raw=True,
)[:5]
@@ -212,7 +212,7 @@ class EditBook(View):
if image:
book.cover.save(*image, save=False)
book.save()
- return redirect("/book/%s" % book.id)
+ return redirect(f"/book/{book.id}")
@method_decorator(login_required, name="dispatch")
@@ -238,14 +238,14 @@ class ConfirmEditBook(View):
# get or create author as needed
for i in range(int(request.POST.get("author-match-count", 0))):
- match = request.POST.get("author_match-%d" % i)
+ match = request.POST.get(f"author_match-{i}")
if not match:
return HttpResponseBadRequest()
try:
# if it's an int, it's an ID
match = int(match)
author = get_object_or_404(
- models.Author, id=request.POST["author_match-%d" % i]
+ models.Author, id=request.POST[f"author_match-{i}"]
)
except ValueError:
# otherwise it's a name
@@ -267,7 +267,7 @@ class ConfirmEditBook(View):
for author_id in request.POST.getlist("remove_authors"):
book.authors.remove(author_id)
- return redirect("/book/%s" % book.id)
+ return redirect(f"/book/{book.id}")
@login_required
@@ -283,7 +283,7 @@ def upload_cover(request, book_id):
if image:
book.cover.save(*image)
- return redirect("{:s}?cover_error=True".format(book.local_path))
+ return redirect(f"{book.local_path}?cover_error=True")
form = forms.CoverForm(request.POST, request.FILES, instance=book)
if not form.is_valid() or not form.files.get("cover"):