From 719df5621ce06a9f33e2072c98fe797168e10e55 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 11:58:03 -0800 Subject: [PATCH 1/5] Unit test to catch error on list page --- bookwyrm/tests/views/lists/test_list.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/tests/views/lists/test_list.py b/bookwyrm/tests/views/lists/test_list.py index a999d4cd..f29288c0 100644 --- a/bookwyrm/tests/views/lists/test_list.py +++ b/bookwyrm/tests/views/lists/test_list.py @@ -85,6 +85,7 @@ class ListViews(TestCase): user=self.local_user, book=self.book, approved=True, + notes="hello", order=1, ) From fefb7e582a4bc01df5fe7a6608d78acdc551b396 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 12:02:10 -0800 Subject: [PATCH 2/5] Fixes list note display --- bookwyrm/templates/lists/list.html | 4 +--- bookwyrm/tests/views/lists/test_list.py | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index a4c12f46..6dfea8a6 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -84,9 +84,7 @@ {{ username }} says: {% endblocktrans %} -

- {{ item.notes|to_markdown|safe }} -

+ {{ item.notes|to_markdown|safe }} {% if item.user == request.user %}
diff --git a/bookwyrm/tests/views/lists/test_list.py b/bookwyrm/tests/views/lists/test_list.py index f29288c0..bcec0822 100644 --- a/bookwyrm/tests/views/lists/test_list.py +++ b/bookwyrm/tests/views/lists/test_list.py @@ -179,6 +179,7 @@ class ListViews(TestCase): book_list=self.list, user=self.local_user, book=self.book, + notes="hi hello", approved=True, order=1, ) From 0683ce1c33f5341dc1ae7c6c8c805a745a763201 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 12:06:47 -0800 Subject: [PATCH 3/5] Proper markdown formatting --- .../migrations/0133_alter_listitem_notes.py | 21 +++++++++++++++++++ bookwyrm/models/list.py | 2 +- bookwyrm/views/list/list_item.py | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 bookwyrm/migrations/0133_alter_listitem_notes.py diff --git a/bookwyrm/migrations/0133_alter_listitem_notes.py b/bookwyrm/migrations/0133_alter_listitem_notes.py new file mode 100644 index 00000000..26ed10f8 --- /dev/null +++ b/bookwyrm/migrations/0133_alter_listitem_notes.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.11 on 2022-02-04 20:06 + +import bookwyrm.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0132_alter_user_preferred_language"), + ] + + operations = [ + migrations.AlterField( + model_name="listitem", + name="notes", + field=bookwyrm.models.fields.HtmlField( + blank=True, max_length=300, null=True + ), + ), + ] diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 7dff7214..ea524cc5 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -142,7 +142,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel): user = fields.ForeignKey( "User", on_delete=models.PROTECT, activitypub_field="actor" ) - notes = fields.TextField(blank=True, null=True, max_length=300) + notes = fields.HtmlField(blank=True, null=True, max_length=300) approved = models.BooleanField(default=True) order = fields.IntegerField() endorsement = models.ManyToManyField("User", related_name="endorsers") diff --git a/bookwyrm/views/list/list_item.py b/bookwyrm/views/list/list_item.py index 5fd65938..6dca908f 100644 --- a/bookwyrm/views/list/list_item.py +++ b/bookwyrm/views/list/list_item.py @@ -5,6 +5,7 @@ from django.utils.decorators import method_decorator from django.views import View from bookwyrm import forms, models +from bookwyrm.views.status import to_markdown # pylint: disable=no-self-use @@ -18,7 +19,9 @@ class ListItem(View): list_item.raise_not_editable(request.user) form = forms.ListItemForm(request.POST, instance=list_item) if form.is_valid(): - form.save() + item = form.save(commit=False) + item.notes = to_markdown(item.notes) + item.save() else: raise Exception(form.errors) return redirect("list", list_item.book_list.id) From 547d2463751fb7fe7c02b4f2ce4b17749c888e03 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 12:09:20 -0800 Subject: [PATCH 4/5] Fixes 500 error --- bookwyrm/templates/lists/list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index 6dfea8a6..ab64fc9b 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -79,7 +79,7 @@
- {% url 'user-feed' user|username as user_path %} + {% url 'user-feed' item.user|username as user_path %} {% blocktrans trimmed with username=user.display_name %} {{ username }} says: {% endblocktrans %} From 18768a23f3a8d81688490d18746a1dfca7b05acf Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 15:30:58 -0800 Subject: [PATCH 5/5] Fixes test --- bookwyrm/tests/views/lists/test_list_item.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/lists/test_list_item.py b/bookwyrm/tests/views/lists/test_list_item.py index 0d6f66ab..50be3c28 100644 --- a/bookwyrm/tests/views/lists/test_list_item.py +++ b/bookwyrm/tests/views/lists/test_list_item.py @@ -67,4 +67,4 @@ class ListItemViews(TestCase): self.assertEqual(mock.call_count, 1) item.refresh_from_db() - self.assertEqual(item.notes, "beep boop") + self.assertEqual(item.notes, "

beep boop

")