diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index efc9d8da2..4ddc8eb9a 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -400,11 +400,11 @@ def get_representative(): to sign outgoing HTTP GET requests""" return models.User.objects.get_or_create( username=f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}", - defaults=dict( - email="bookwyrm@localhost", - local=True, - localname=INSTANCE_ACTOR_USERNAME, - ), + defaults={ + "email": "bookwyrm@localhost", + "local": True, + "localname": INSTANCE_ACTOR_USERNAME, + }, )[0] diff --git a/bookwyrm/importers/calibre_import.py b/bookwyrm/importers/calibre_import.py index 5c22a539d..542175dd7 100644 --- a/bookwyrm/importers/calibre_import.py +++ b/bookwyrm/importers/calibre_import.py @@ -14,15 +14,10 @@ class CalibreImporter(Importer): def __init__(self, *args: Any, **kwargs: Any): # Add timestamp to row_mappings_guesses for date_added to avoid # integrity error - row_mappings_guesses = [] - - for field, mapping in self.row_mappings_guesses: - if field in ("date_added",): - row_mappings_guesses.append((field, mapping + ["timestamp"])) - else: - row_mappings_guesses.append((field, mapping)) - - self.row_mappings_guesses = row_mappings_guesses + self.row_mappings_guesses = [ + (field, mapping + (["timestamp"] if field == "date_added" else [])) + for field, mapping in self.row_mappings_guesses + ] super().__init__(*args, **kwargs) def get_shelf(self, normalized_row: dict[str, Optional[str]]) -> Optional[str]: diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index 0015c5fe1..06ef373e6 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -169,7 +169,7 @@ class ActivitypubMixin: # filter users first by whether they're using the desired software # this lets us send book updates only to other bw servers if software: - queryset = queryset.filter(bookwyrm_user=(software == "bookwyrm")) + queryset = queryset.filter(bookwyrm_user=software == "bookwyrm") # if there's a user, we only want to send to the user's followers if user: queryset = queryset.filter(following=user) diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index bc87a60d7..ab597a22a 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -137,14 +137,14 @@ def get_file_size(nbytes): raw_size = float(nbytes) except (ValueError, TypeError): return repr(nbytes) - else: - if raw_size < 1024: - return f"{raw_size} bytes" - if raw_size < 1024**2: - return f"{raw_size/1024:.2f} KB" - if raw_size < 1024**3: - return f"{raw_size/1024**2:.2f} MB" - return f"{raw_size/1024**3:.2f} GB" + + if raw_size < 1024: + return f"{raw_size} bytes" + if raw_size < 1024**2: + return f"{raw_size/1024:.2f} KB" + if raw_size < 1024**3: + return f"{raw_size/1024**2:.2f} MB" + return f"{raw_size/1024**3:.2f} GB" @register.filter(name="get_user_permission") diff --git a/bookwyrm/tests/validate_html.py b/bookwyrm/tests/validate_html.py index 748b94d5f..11bc84880 100644 --- a/bookwyrm/tests/validate_html.py +++ b/bookwyrm/tests/validate_html.py @@ -35,7 +35,7 @@ def validate_html(html): e for e in errors.split("\n") if not any(exclude in e for exclude in excluded) ) if errors: - raise Exception(errors) + raise ValueError(errors) validator = HtmlValidator() # will raise exceptions @@ -62,6 +62,6 @@ class HtmlValidator(HTMLParser): # pylint: disable=abstract-method and "noreferrer" in value ): return - raise Exception( + raise ValueError( 'Links to a new tab must have rel="nofollow noopener noreferrer"' ) diff --git a/bookwyrm/views/annual_summary.py b/bookwyrm/views/annual_summary.py index 703a2d2ab..21ac53992 100644 --- a/bookwyrm/views/annual_summary.py +++ b/bookwyrm/views/annual_summary.py @@ -225,4 +225,4 @@ def get_goal_status(user, year): if goal.privacy != "public": return None - return dict(**goal.progress, **{"goal": goal.goal}) + return {**goal.progress, **{"goal": goal.goal}}