Updating string format synatx part 3

This commit is contained in:
Mouse Reeve 2021-09-20 16:44:59 -07:00
parent cf3157a3b5
commit ea303fb285
6 changed files with 22 additions and 17 deletions

View file

@ -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"""

View file

@ -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}<p>(comment on <a href="{self.book.remote_id}">"{self.book.title}"</a>)</p>'
return (
f'{self.content}<p>(comment on <a href="{self.book.remote_id}">'
'"{self.book.title}"</a>)</p>'
)
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"^<p>", '<p>"', self.quote)
quote = re.sub(r"</p>$", '"</p>', quote)
return f'{quote} <p>-- <a href="{self.book.remote_id}">"{self.book.title}"</a></p>{self.content}'
return (
f'{quote} <p>-- <a href="{self.book.remote_id}">'
'"{self.book.title}"</a></p>{self.content}'
)
activity_serializer = activitypub.Quotation

View file

@ -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)]

View file

@ -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__)))

View file

@ -20,8 +20,8 @@ status_types = [
"generatednote",
]
status_types_string = "|".join(status_types)
STATUS_PATH = rf"{USER_PATH}/({status_types_string})/(?P<status_id>\d+)"
STATUS_TYPES_STRING = "|".join(status_types)
STATUS_PATH = rf"{USER_PATH}/({STATUS_TYPES_STRING})/(?P<status_id>\d+)"
BOOK_PATH = r"^book/(?P<book_id>\d+)"

View file

@ -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"):