Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion list #3420

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
434cb7e
Create suggestion list
joachimesque Jan 1, 2023
acd3799
Add list creation button
joachimesque Jan 1, 2023
fe05e31
Fix field doc
joachimesque Jan 1, 2023
25af64f
Display books in list
joachimesque Jan 1, 2023
4712673
Add book suggestion
joachimesque Jan 1, 2023
aee1af5
black ✨ 🍰 ✨
joachimesque Jan 1, 2023
3cb548f
Switch from subclass to new column
joachimesque Jan 1, 2023
630bbc1
Update template with new column names
joachimesque Jan 1, 2023
6de97ae
Add get_name for dynamically generated name and description
joachimesque Jan 1, 2023
f81c161
Limit what's displayed on list page
joachimesque Jan 1, 2023
067ce29
black
joachimesque Jan 1, 2023
2faaea6
docstrings
joachimesque Jan 1, 2023
62c9c71
Replace ignore_id with ignore_book
joachimesque Jan 1, 2023
80ce4ec
Display the right lists in the Book sidebar
joachimesque Jan 1, 2023
88da825
Update ordered_collection.py
joachimesque Jan 1, 2023
bee38cd
Add defauult
joachimesque Jan 1, 2023
23b0219
Merge branch 'main' into suggestion-list
joachimesque Jan 6, 2023
b88df90
Merge branch 'main' into suggestion-list
mouse-reeve Jan 11, 2023
a9347f7
Merge branch 'main' into suggestion-list
joachimesque Aug 1, 2023
486278b
Black 🕴️
joachimesque Aug 1, 2023
0f93833
Update migration
joachimesque Aug 1, 2023
9d6136e
Merge branch 'main' into suggestion-list
mouse-reeve Aug 26, 2024
8dc8196
Updates migration to avoid involved merge
mouse-reeve Aug 26, 2024
7603d18
Wrap card columns in suggestions list
mouse-reeve Aug 26, 2024
cc70e83
Re-styles suggstions to show the recommender's notes
mouse-reeve Aug 26, 2024
68fa3de
Makes "add suggestions" section a detail element
mouse-reeve Aug 26, 2024
e8a95a2
Moves book suggestion markup to a snippet
mouse-reeve Aug 26, 2024
5ea9358
Only show three suggestions on the book page
mouse-reeve Aug 26, 2024
500bd84
hide description if note is present for suggestion card
mouse-reeve Aug 26, 2024
ed5ae4a
Merge branch 'main' into suggestion-list
mouse-reeve Aug 26, 2024
01d7088
Show suggestion list suggestions in columns
mouse-reeve Aug 26, 2024
6b615d4
Adds a couple suggestions tests
mouse-reeve Aug 26, 2024
0034653
Uses a separate model for suggestion lists
mouse-reeve Aug 27, 2024
5879b4b
Adds missing view file
mouse-reeve Aug 27, 2024
2e15c22
Fixes adding books from list page view
mouse-reeve Aug 27, 2024
c901d76
Allow users to remove books from suggestion lists
mouse-reeve Aug 27, 2024
5f906e3
Updates migrations
mouse-reeve Aug 27, 2024
12291c9
Adds endorsement functionality
mouse-reeve Aug 27, 2024
782ca09
Updates tests
mouse-reeve Aug 27, 2024
c95408a
Merge branch 'main' into suggestion-list
mouse-reeve Aug 27, 2024
299ac06
adds merge migration
mouse-reeve Aug 27, 2024
5deb779
Associate suggestions with works instead of editions
mouse-reeve Aug 27, 2024
1bccffa
Uses separate activitypub type of suggestion lists
mouse-reeve Aug 27, 2024
aee089f
Support suggestion filtering when ignore book isn't present
mouse-reeve Aug 27, 2024
6b622ba
Adds more tests
mouse-reeve Aug 27, 2024
0b171b0
Adds type annotation to suggestion list view file
mouse-reeve Aug 28, 2024
b5b9a4f
Fixes placement of ignores that black muddled (rude)
mouse-reeve Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bookwyrm/activitypub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .note import Tombstone
from .ordered_collection import OrderedCollection, OrderedCollectionPage
from .ordered_collection import CollectionItem, ListItem, ShelfItem
from .ordered_collection import BookList, Shelf
from .ordered_collection import BookList, SuggestionList, Shelf
from .person import Person, PublicKey
from .response import ActivitypubResponse
from .book import Edition, Work, Author
Expand Down
9 changes: 9 additions & 0 deletions bookwyrm/activitypub/ordered_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ class BookList(OrderedCollectionPrivate):
type: str = "BookList"


@dataclass(init=False)
class SuggestionList(OrderedCollectionPrivate):
"""structure of an ordered collection activity"""

summary: str = None
book: str = None
type: str = "SuggestionList"


# pylint: disable=invalid-name
@dataclass(init=False)
class OrderedCollectionPage(ActivityObject):
Expand Down
12 changes: 12 additions & 0 deletions bookwyrm/forms/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ class Meta:
fields = ["user", "book", "book_list", "notes"]


class SuggestionListForm(CustomForm):
class Meta:
model = models.SuggestionList
fields = ["suggests_for"]


class SuggestionListItemForm(CustomForm):
class Meta:
model = models.SuggestionListItem
fields = ["user", "book", "book_list", "notes"]


class SortListForm(forms.Form):
sort_by = ChoiceField(
choices=(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Generated by Django 4.2.15 on 2024-08-27 17:27

import bookwyrm.models.activitypub_mixin
import bookwyrm.models.fields
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0209_user_show_ratings"),
]

operations = [
migrations.CreateModel(
name="SuggestionList",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_date", models.DateTimeField(auto_now_add=True)),
("updated_date", models.DateTimeField(auto_now=True)),
(
"remote_id",
bookwyrm.models.fields.RemoteIdField(
max_length=255,
null=True,
validators=[bookwyrm.models.fields.validate_remote_id],
),
),
("embed_key", models.UUIDField(editable=False, null=True, unique=True)),
(
"privacy",
bookwyrm.models.fields.PrivacyField(
choices=[
("public", "Public"),
("unlisted", "Unlisted"),
("followers", "Followers"),
("direct", "Private"),
],
default="public",
max_length=255,
),
),
],
options={
"ordering": ("-updated_date",),
"abstract": False,
},
bases=(
bookwyrm.models.activitypub_mixin.OrderedCollectionMixin,
models.Model,
),
),
migrations.AlterModelOptions(
name="listitem",
options={},
),
migrations.CreateModel(
name="SuggestionListItem",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_date", models.DateTimeField(auto_now_add=True)),
("updated_date", models.DateTimeField(auto_now=True)),
(
"remote_id",
bookwyrm.models.fields.RemoteIdField(
max_length=255,
null=True,
validators=[bookwyrm.models.fields.validate_remote_id],
),
),
(
"notes",
bookwyrm.models.fields.HtmlField(
blank=True, max_length=300, null=True
),
),
(
"book",
bookwyrm.models.fields.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="bookwyrm.edition",
),
),
(
"book_list",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="bookwyrm.suggestionlist",
),
),
(
"endorsement",
models.ManyToManyField(
related_name="suggestion_endorsers", to=settings.AUTH_USER_MODEL
),
),
(
"user",
bookwyrm.models.fields.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"ordering": ("-created_date",),
"abstract": False,
"unique_together": {("book", "book_list")},
},
bases=(bookwyrm.models.activitypub_mixin.CollectionItemMixin, models.Model),
),
migrations.AddField(
model_name="suggestionlist",
name="books",
field=models.ManyToManyField(
through="bookwyrm.SuggestionListItem", to="bookwyrm.edition"
),
),
migrations.AddField(
model_name="suggestionlist",
name="suggests_for",
field=bookwyrm.models.fields.OneToOneField(
on_delete=django.db.models.deletion.PROTECT,
related_name="suggestion_list",
to="bookwyrm.work",
),
),
migrations.AddField(
model_name="suggestionlist",
name="user",
field=bookwyrm.models.fields.ForeignKey(
on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL
),
),
]
1 change: 1 addition & 0 deletions bookwyrm/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from .shelf import Shelf, ShelfBook
from .list import List, ListItem
from .list import SuggestionList, SuggestionListItem

from .status import Status, GeneratedNote, Comment, Quotation
from .status import Review, ReviewRating
Expand Down
6 changes: 3 additions & 3 deletions bookwyrm/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def field_to_activity(self, value):


class OneToOneField(ActivitypubRelatedFieldMixin, models.OneToOneField):
"""activitypub-aware foreign key field"""
"""activitypub-aware one to one field"""

def field_to_activity(self, value):
if not value:
Expand Down Expand Up @@ -621,11 +621,11 @@ class BooleanField(ActivitypubFieldMixin, models.BooleanField):


class IntegerField(ActivitypubFieldMixin, models.IntegerField):
"""activitypub-aware boolean field"""
"""activitypub-aware integer field"""


class DecimalField(ActivitypubFieldMixin, models.DecimalField):
"""activitypub-aware boolean field"""
"""activitypub-aware decimal field"""

def field_to_activity(self, value):
if not value:
Expand Down
Loading
Loading