diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index f8d3b78187..eeb2e940d1 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -8,6 +8,7 @@ from django.dispatch import receiver from django.http import Http404 from django.utils.translation import gettext_lazy as _ +from django.utils.text import slugify from bookwyrm.settings import DOMAIN from .fields import RemoteIdField @@ -35,10 +36,11 @@ class BookWyrmModel(models.Model): remote_id = RemoteIdField(null=True, activitypub_field="id") def get_remote_id(self): - """generate a url that resolves to the local object""" + """generate the url that resolves to the local object, without a slug""" base_path = f"https://{DOMAIN}" if hasattr(self, "user"): base_path = f"{base_path}{self.user.local_path}" + model_name = type(self).__name__.lower() return f"{base_path}/{model_name}/{self.id}" @@ -49,8 +51,20 @@ class Meta: @property def local_path(self): - """how to link to this object in the local app""" - return self.get_remote_id().replace(f"https://{DOMAIN}", "") + """how to link to this object in the local app, with a slug""" + local = self.get_remote_id().replace(f"https://{DOMAIN}", "") + + name = None + if hasattr(self, "name_field"): + name = getattr(self, self.name_field) + elif hasattr(self, "name"): + name = self.name + + if name: + slug = slugify(name) + local = f"{local}/s/{slug}" + + return local def raise_visible_to_user(self, viewer): """is a user authorized to view an object?""" diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py index 320d495d27..8ea274ea1f 100644 --- a/bookwyrm/models/shelf.py +++ b/bookwyrm/models/shelf.py @@ -6,6 +6,7 @@ from django.utils import timezone from bookwyrm import activitypub +from bookwyrm.settings import DOMAIN from .activitypub_mixin import CollectionItemMixin, OrderedCollectionMixin from .base_model import BookWyrmModel from . import fields @@ -65,6 +66,11 @@ def get_remote_id(self): identifier = self.identifier or self.get_identifier() return f"{base_path}/books/{identifier}" + @property + def local_path(self): + """No slugs""" + return self.get_remote_id().replace(f"https://{DOMAIN}", "") + def raise_not_deletable(self, viewer): """don't let anyone delete a default shelf""" super().raise_not_deletable(viewer) diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 453480f999..e7d10f4f3a 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -284,7 +284,7 @@

{% trans "Your reading activity" %}

{% if user_statuses.review_count or user_statuses.comment_count or user_statuses.quotation_count %}