diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index 78d153a21..d06c84516 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -55,7 +55,7 @@ class Author(BookDataModel): """generate the url from the openlibrary id""" return f"https://openlibrary.org/authors/{self.openlibrary_key}" - def get_remote_id(self): + def get_permalink(self): """editions and works both use "book" instead of model_name""" return f"https://{DOMAIN}/author/{self.id}" diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index f8d3b7818..f729efb8a 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -8,6 +8,7 @@ from django.db.models import Q 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 @@ -34,14 +35,31 @@ class BookWyrmModel(models.Model): updated_date = models.DateTimeField(auto_now=True) remote_id = RemoteIdField(null=True, activitypub_field="id") - def get_remote_id(self): - """generate a url that resolves to the local object""" + def get_permalink(self): + """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}" + def get_remote_id(self): + """generate a url that resolves to the local object, with a slug suffix""" + path = self.get_permalink() + + 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) + path = f"{path}/s/{slug}" + + return path + class Meta: """this is just here to provide default fields for other models""" diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 3ea8e1a8e..c1a2ee2c9 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -203,7 +203,7 @@ class Book(BookDataModel): return super().save(*args, **kwargs) - def get_remote_id(self): + def get_permalink(self): """editions and works both use "book" instead of model_name""" return f"https://{DOMAIN}/book/{self.id}" diff --git a/bookwyrm/models/group.py b/bookwyrm/models/group.py index 05ed39a27..7ed6f3322 100644 --- a/bookwyrm/models/group.py +++ b/bookwyrm/models/group.py @@ -16,7 +16,7 @@ class Group(BookWyrmModel): description = fields.TextField(blank=True, null=True) privacy = fields.PrivacyField() - def get_remote_id(self): + def get_permalink(self): """don't want the user to be in there in this case""" return f"https://{DOMAIN}/group/{self.id}" diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index ea524cc54..9cf68a6ed 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -49,7 +49,7 @@ class List(OrderedCollectionMixin, BookWyrmModel): embed_key = models.UUIDField(unique=True, null=True, editable=False) activity_serializer = activitypub.BookList - def get_remote_id(self): + def get_permalink(self): """don't want the user to be in there in this case""" return f"https://{DOMAIN}/list/{self.id}" diff --git a/bookwyrm/models/relationship.py b/bookwyrm/models/relationship.py index e95c38fa5..49968b718 100644 --- a/bookwyrm/models/relationship.py +++ b/bookwyrm/models/relationship.py @@ -62,7 +62,7 @@ class UserRelationship(BookWyrmModel): ), ] - def get_remote_id(self): + def get_permalink(self): """use shelf identifier in remote_id""" base_path = self.user_subject.remote_id return f"{base_path}#follows/{self.id}" diff --git a/bookwyrm/models/report.py b/bookwyrm/models/report.py index bf3184f52..d6bcf17c7 100644 --- a/bookwyrm/models/report.py +++ b/bookwyrm/models/report.py @@ -21,7 +21,7 @@ class Report(BookWyrmModel): links = models.ManyToManyField("Link", blank=True) resolved = models.BooleanField(default=False) - def get_remote_id(self): + def get_permalink(self): return f"https://{DOMAIN}/settings/reports/{self.id}" class Meta: diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py index 320d495d2..749049e35 100644 --- a/bookwyrm/models/shelf.py +++ b/bookwyrm/models/shelf.py @@ -59,7 +59,7 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel): """can the shelf be safely deleted?""" return self.editable and not self.shelfbook_set.exists() - def get_remote_id(self): + def get_permalink(self): """shelf identifier instead of id""" base_path = self.user.remote_id identifier = self.identifier or self.get_identifier() diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index be5c19922..65ecad9e9 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -396,7 +396,7 @@ class KeyPair(ActivitypubMixin, BookWyrmModel): activity_serializer = activitypub.PublicKey serialize_reverse_fields = [("owner", "owner", "id")] - def get_remote_id(self): + def get_permalink(self): # self.owner is set by the OneToOneField on User return f"{self.owner.remote_id}/#main-key" @@ -430,7 +430,7 @@ class AnnualGoal(BookWyrmModel): unique_together = ("user", "year") - def get_remote_id(self): + def get_permalink(self): """put the year in the path""" return f"{self.user.remote_id}/goal/{self.year}" diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 0e2fd5d39..9154fd783 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -267,7 +267,7 @@ {% if user_statuses.review_count or user_statuses.comment_count or user_statuses.quotation_count %}