diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 8ae75baf..97969ccf 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -44,6 +44,7 @@ class BookDataModel(ObjectMixin, BookWyrmModel): bnf_id = fields.CharField( # Bibliothèque nationale de France max_length=255, blank=True, null=True, deduplication_field=True ) + links = fields.ManyToManyField("Link") search_vector = SearchVectorField(null=True) last_edited_by = fields.ForeignKey( @@ -104,6 +105,7 @@ class Book(BookDataModel): objects = InheritanceManager() field_tracker = FieldTracker(fields=["authors", "title", "subtitle", "cover"]) + file_links = fields.ManyToManyField("FileLink") if ENABLE_THUMBNAIL_GENERATION: cover_bw_book_xsmall_webp = ImageSpecField( diff --git a/bookwyrm/models/link.py b/bookwyrm/models/link.py new file mode 100644 index 00000000..47c65afd --- /dev/null +++ b/bookwyrm/models/link.py @@ -0,0 +1,17 @@ +""" outlink data """ +from .activitypub_mixin import CollectionItemMixin +from .base_model import BookWyrmModel +from . import fields + +class Link(CollectionItemMixin, BookWyrmModel): + """a link to a website""" + + url = fields.CharField(max_length=255) + name = fields.CharField(max_length=255) + + +class FileLink(Link): + """a link to a file""" + + filetype = fields.CharField(max_length=5) + filetype_description = fields.CharField(max_length=100) diff --git a/bookwyrm/suggested_users.py b/bookwyrm/suggested_users.py index e8f23632..aa53fcb2 100644 --- a/bookwyrm/suggested_users.py +++ b/bookwyrm/suggested_users.py @@ -148,6 +148,17 @@ def update_suggestions_on_follow(sender, instance, created, *args, **kwargs): rerank_user_task.delay(instance.user_object.id, update_only=False) +@receiver(signals.post_save, sender=models.UserFollowRequest) +# pylint: disable=unused-argument +def update_suggestions_on_follow_request(sender, instance, created, *args, **kwargs): + """remove a follow from the recs and update the ranks""" + if not created or not instance.user_object.discoverable: + return + + if instance.user_subject.local: + remove_suggestion_task.delay(instance.user_subject.id, instance.user_object.id) + + @receiver(signals.post_save, sender=models.UserBlocks) # pylint: disable=unused-argument def update_suggestions_on_block(sender, instance, *args, **kwargs): diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 63c5c768..d664c6ff 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -48,6 +48,7 @@ from .isbn import Isbn from .landing import About, Home, Landing from .list import Lists, SavedLists, List, Curate, UserLists from .list import save_list, unsave_list, delete_list +from .link import Link, FileLink from .login import Login, Logout from .notifications import Notifications from .outbox import Outbox