forked from mirrors/bookwyrm
Updating string format synatx part 3
This commit is contained in:
parent
cf3157a3b5
commit
ea303fb285
6 changed files with 22 additions and 17 deletions
|
@ -20,9 +20,8 @@ class ActivityStream(RedisStore):
|
||||||
|
|
||||||
def unread_id(self, user):
|
def unread_id(self, user):
|
||||||
"""the redis key for this user's unread count for this stream"""
|
"""the redis key for this user's unread count for this stream"""
|
||||||
return "{}-unread".format(
|
stream_id = self.stream_id(user)
|
||||||
self.stream_id(user)
|
return f"{stream_id}-unread"
|
||||||
) # pylint: disable=consider-using-f-string
|
|
||||||
|
|
||||||
def get_rank(self, obj): # pylint: disable=no-self-use
|
def get_rank(self, obj): # pylint: disable=no-self-use
|
||||||
"""statuses are sorted by date published"""
|
"""statuses are sorted by date published"""
|
||||||
|
|
|
@ -277,7 +277,10 @@ class Comment(BookStatus):
|
||||||
@property
|
@property
|
||||||
def pure_content(self):
|
def pure_content(self):
|
||||||
"""indicate the book in question for mastodon (or w/e) users"""
|
"""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
|
activity_serializer = activitypub.Comment
|
||||||
|
|
||||||
|
@ -302,7 +305,10 @@ class Quotation(BookStatus):
|
||||||
"""indicate the book in question for mastodon (or w/e) users"""
|
"""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>"', self.quote)
|
||||||
quote = re.sub(r"</p>$", '"</p>', 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
|
activity_serializer = activitypub.Quotation
|
||||||
|
|
||||||
|
|
|
@ -220,6 +220,7 @@ def generate_default_inner_img():
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-locals
|
# pylint: disable=too-many-locals
|
||||||
|
# pylint: disable=too-many-statements
|
||||||
def generate_preview_image(
|
def generate_preview_image(
|
||||||
texts=None, picture=None, rating=None, show_instance_layer=True
|
texts=None, picture=None, rating=None, show_instance_layer=True
|
||||||
):
|
):
|
||||||
|
@ -237,7 +238,8 @@ def generate_preview_image(
|
||||||
|
|
||||||
# Color
|
# Color
|
||||||
if BG_COLOR in ["use_dominant_color_light", "use_dominant_color_dark"]:
|
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
|
# Adjust color
|
||||||
image_bg_color_rgb = [x / 255.0 for x in ImageColor.getrgb(image_bg_color)]
|
image_bg_color_rgb = [x / 255.0 for x in ImageColor.getrgb(image_bg_color)]
|
||||||
|
|
|
@ -23,9 +23,7 @@ EMAIL_HOST_USER = env("EMAIL_HOST_USER")
|
||||||
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
|
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
|
||||||
EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True)
|
EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True)
|
||||||
EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", False)
|
EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", False)
|
||||||
DEFAULT_FROM_EMAIL = "admin@{:s}".format(
|
DEFAULT_FROM_EMAIL = f"admin@{DOMAIN}"
|
||||||
env("DOMAIN")
|
|
||||||
) # pylint: disable=consider-using-f-string
|
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
|
@ -20,8 +20,8 @@ status_types = [
|
||||||
"generatednote",
|
"generatednote",
|
||||||
]
|
]
|
||||||
|
|
||||||
status_types_string = "|".join(status_types)
|
STATUS_TYPES_STRING = "|".join(status_types)
|
||||||
STATUS_PATH = rf"{USER_PATH}/({status_types_string})/(?P<status_id>\d+)"
|
STATUS_PATH = rf"{USER_PATH}/({STATUS_TYPES_STRING})/(?P<status_id>\d+)"
|
||||||
|
|
||||||
BOOK_PATH = r"^book/(?P<book_id>\d+)"
|
BOOK_PATH = r"^book/(?P<book_id>\d+)"
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ class EditBook(View):
|
||||||
# check if this is an edition of an existing work
|
# check if this is an edition of an existing work
|
||||||
author_text = book.author_text if book else add_author
|
author_text = book.author_text if book else add_author
|
||||||
data["book_matches"] = connector_manager.local_search(
|
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,
|
min_confidence=0.5,
|
||||||
raw=True,
|
raw=True,
|
||||||
)[:5]
|
)[:5]
|
||||||
|
@ -212,7 +212,7 @@ class EditBook(View):
|
||||||
if image:
|
if image:
|
||||||
book.cover.save(*image, save=False)
|
book.cover.save(*image, save=False)
|
||||||
book.save()
|
book.save()
|
||||||
return redirect("/book/%s" % book.id)
|
return redirect(f"/book/{book.id}")
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name="dispatch")
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@ -238,14 +238,14 @@ class ConfirmEditBook(View):
|
||||||
|
|
||||||
# get or create author as needed
|
# get or create author as needed
|
||||||
for i in range(int(request.POST.get("author-match-count", 0))):
|
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:
|
if not match:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
try:
|
try:
|
||||||
# if it's an int, it's an ID
|
# if it's an int, it's an ID
|
||||||
match = int(match)
|
match = int(match)
|
||||||
author = get_object_or_404(
|
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:
|
except ValueError:
|
||||||
# otherwise it's a name
|
# otherwise it's a name
|
||||||
|
@ -267,7 +267,7 @@ class ConfirmEditBook(View):
|
||||||
for author_id in request.POST.getlist("remove_authors"):
|
for author_id in request.POST.getlist("remove_authors"):
|
||||||
book.authors.remove(author_id)
|
book.authors.remove(author_id)
|
||||||
|
|
||||||
return redirect("/book/%s" % book.id)
|
return redirect(f"/book/{book.id}")
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -283,7 +283,7 @@ def upload_cover(request, book_id):
|
||||||
if image:
|
if image:
|
||||||
book.cover.save(*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)
|
form = forms.CoverForm(request.POST, request.FILES, instance=book)
|
||||||
if not form.is_valid() or not form.files.get("cover"):
|
if not form.is_valid() or not form.files.get("cover"):
|
||||||
|
|
Loading…
Reference in a new issue