diff --git a/bookwyrm/activitypub/__init__.py b/bookwyrm/activitypub/__init__.py index 05ca44476..2697620f0 100644 --- a/bookwyrm/activitypub/__init__.py +++ b/bookwyrm/activitypub/__init__.py @@ -4,7 +4,11 @@ import sys from .base_activity import ActivityEncoder, Signature, naive_parse from .base_activity import Link, Mention, Hashtag -from .base_activity import ActivitySerializerError, resolve_remote_id +from .base_activity import ( + ActivitySerializerError, + resolve_remote_id, + get_representative, +) from .image import Document, Image from .note import Note, GeneratedNote, Article, Comment, Quotation from .note import Review, Rating diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 615db440a..05e7d8a05 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -1,4 +1,5 @@ """ basics for an activitypub serializer """ +from __future__ import annotations from dataclasses import dataclass, fields, MISSING from json import JSONEncoder import logging @@ -72,8 +73,10 @@ class ActivityObject: def __init__( self, - activity_objects: Optional[list[str, base_model.BookWyrmModel]] = None, - **kwargs: dict[str, Any], + activity_objects: Optional[ + dict[str, Union[str, list[str], ActivityObject, base_model.BookWyrmModel]] + ] = None, + **kwargs: Any, ): """this lets you pass in an object with fields that aren't in the dataclass, which it ignores. Any field in the dataclass is required or diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index 5c0c087b2..981e3c0cc 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -1,5 +1,7 @@ """ database schema for info about authors """ import re +from typing import Tuple, Any + from django.contrib.postgres.indexes import GinIndex from django.db import models @@ -38,7 +40,7 @@ class Author(BookDataModel): ) bio = fields.HtmlField(null=True, blank=True) - def save(self, *args, **kwargs): + def save(self, *args: Tuple[Any, ...], **kwargs: dict[str, Any]) -> None: """normalize isni format""" if self.isni: self.isni = re.sub(r"\s", "", self.isni) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index e51f2ba07..5d6109468 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -1,5 +1,6 @@ """ models for storing different kinds of Activities """ from dataclasses import MISSING +from typing import Optional import re from django.apps import apps @@ -269,7 +270,7 @@ class GeneratedNote(Status): """indicate the book in question for mastodon (or w/e) users""" message = self.content books = ", ".join( - f'"{book.title}"' + f'{book.title}' for book in self.mention_books.all() ) return f"{self.user.display_name} {message} {books}" @@ -320,17 +321,14 @@ class Comment(BookStatus): @property def pure_content(self): """indicate the book in question for mastodon (or w/e) users""" - if self.progress_mode == "PG" and self.progress and (self.progress > 0): - return_value = ( - f'{self.content}

(comment on ' - f'"{self.book.title}", page {self.progress})

' - ) - else: - return_value = ( - f'{self.content}

(comment on ' - f'"{self.book.title}")

' - ) - return return_value + progress = self.progress or 0 + citation = ( + f'comment on ' + f"{self.book.title}" + ) + if self.progress_mode == "PG" and progress > 0: + citation += f", p. {progress}" + return f"{self.content}

({citation})

" activity_serializer = activitypub.Comment @@ -354,22 +352,24 @@ class Quotation(BookStatus): blank=True, ) + def _format_position(self) -> Optional[str]: + """serialize page position""" + beg = self.position + end = self.endposition or 0 + if self.position_mode != "PG" or not beg: + return None + return f"pp. {beg}-{end}" if end > beg else f"p. {beg}" + @property def pure_content(self): """indicate the book in question for mastodon (or w/e) users""" quote = re.sub(r"^

", '

"', self.quote) quote = re.sub(r"

$", '"

', quote) - if self.position_mode == "PG" and self.position and (self.position > 0): - return_value = ( - f'{quote}

-- ' - f'"{self.book.title}", page {self.position}

{self.content}' - ) - else: - return_value = ( - f'{quote}

-- ' - f'"{self.book.title}"

{self.content}' - ) - return return_value + title, href = self.book.title, self.book.remote_id + citation = f'— {title}' + if position := self._format_position(): + citation += f", {position}" + return f"{quote}

{citation}

{self.content}" activity_serializer = activitypub.Quotation diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 9a4c9b5a4..94ec761db 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -14,7 +14,7 @@ from django.core.exceptions import ImproperlyConfigured env = Env() env.read_env() DOMAIN = env("DOMAIN") -VERSION = "0.6.5" +VERSION = "0.6.6" RELEASE_API = env( "RELEASE_API", @@ -24,7 +24,7 @@ RELEASE_API = env( PAGE_LENGTH = env.int("PAGE_LENGTH", 15) DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") -JS_CACHE = "b972a43c" +JS_CACHE = "ac315a3b" # email EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend") @@ -317,6 +317,7 @@ LANGUAGES = [ LANGUAGE_ARTICLES = { "English": {"the", "a", "an"}, + "Español (Spanish)": {"un", "una", "unos", "unas", "el", "la", "los", "las"}, } TIME_ZONE = "UTC" diff --git a/bookwyrm/static/js/autocomplete.js b/bookwyrm/static/js/autocomplete.js index 84474e43c..a98cd9634 100644 --- a/bookwyrm/static/js/autocomplete.js +++ b/bookwyrm/static/js/autocomplete.js @@ -106,7 +106,7 @@ const tries = { e: { p: { u: { - b: "ePub", + b: "EPUB", }, }, }, diff --git a/bookwyrm/templates/book/edit/edit_book_form.html b/bookwyrm/templates/book/edit/edit_book_form.html index 23cc6d097..4cc3965e7 100644 --- a/bookwyrm/templates/book/edit/edit_book_form.html +++ b/bookwyrm/templates/book/edit/edit_book_form.html @@ -10,7 +10,7 @@ {% csrf_token %} -{% if form.parent_work %} +{% if book.parent_work.id or form.parent_work %} {% endif %} diff --git a/bookwyrm/templates/book/editions/editions.html b/bookwyrm/templates/book/editions/editions.html index aa2b68bdb..e1766d1e1 100644 --- a/bookwyrm/templates/book/editions/editions.html +++ b/bookwyrm/templates/book/editions/editions.html @@ -5,7 +5,7 @@ {% block content %}
-

{% blocktrans with work_path=work.local_path work_title=work|book_title %}Editions of "{{ work_title }}"{% endblocktrans %}

+

{% blocktrans with work_path=work.local_path work_title=work|book_title %}Editions of {{ work_title }}{% endblocktrans %}

{% include 'book/editions/edition_filters.html' %} diff --git a/bookwyrm/templates/book/file_links/add_link_modal.html b/bookwyrm/templates/book/file_links/add_link_modal.html index 67b437bd7..8ed4389ff 100644 --- a/bookwyrm/templates/book/file_links/add_link_modal.html +++ b/bookwyrm/templates/book/file_links/add_link_modal.html @@ -35,7 +35,7 @@ required="" id="id_filetype" value="{% firstof file_link_form.filetype.value '' %}" - placeholder="ePub" + placeholder="EPUB" list="mimetypes-list" data-autocomplete="mimetype" > diff --git a/bookwyrm/templates/import/import.html b/bookwyrm/templates/import/import.html index 394606c53..ad857fb2e 100644 --- a/bookwyrm/templates/import/import.html +++ b/bookwyrm/templates/import/import.html @@ -18,7 +18,7 @@ {% if import_size_limit and import_limit_reset %}

- {% blocktrans count days=import_limit_reset with display_size=import_size_limit|intcomma %} + {% blocktrans trimmed count days=import_limit_reset with display_size=import_size_limit|intcomma %} Currently, you are allowed to import {{ display_size }} books every {{ import_limit_reset }} day. {% plural %} Currently, you are allowed to import {{ import_size_limit }} books every {{ import_limit_reset }} days. diff --git a/bookwyrm/templates/settings/registration.html b/bookwyrm/templates/settings/registration.html index 3ebfff9ae..5fe5520e5 100644 --- a/bookwyrm/templates/settings/registration.html +++ b/bookwyrm/templates/settings/registration.html @@ -75,13 +75,13 @@ {% include 'snippets/form_errors.html' with errors_list=form.invite_request_text.errors id="desc_invite_request_text" %}

-
-
-