From af567ba05ed285bf3ca33d5a668aeff926c75b60 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 14 Oct 2021 18:34:26 -0700 Subject: [PATCH 1/6] Edit posts in original markdown syntax --- .../migrations/0110_auto_20211015_0128.py | 24 +++++++++++++++++++ bookwyrm/models/status.py | 2 ++ .../snippets/create_status/content_field.html | 2 +- .../snippets/create_status/quotation.html | 2 +- bookwyrm/views/status.py | 5 ++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 bookwyrm/migrations/0110_auto_20211015_0128.py diff --git a/bookwyrm/migrations/0110_auto_20211015_0128.py b/bookwyrm/migrations/0110_auto_20211015_0128.py new file mode 100644 index 000000000..aee378a36 --- /dev/null +++ b/bookwyrm/migrations/0110_auto_20211015_0128.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.5 on 2021-10-15 01:28 + +import bookwyrm.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0109_status_edited"), + ] + + operations = [ + migrations.AddField( + model_name="quotation", + name="raw_quote", + field=bookwyrm.models.fields.HtmlField(blank=True, null=True), + ), + migrations.AddField( + model_name="status", + name="raw_content", + field=bookwyrm.models.fields.HtmlField(blank=True, null=True), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 1027ecb58..fe051056e 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -31,6 +31,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): "User", on_delete=models.PROTECT, activitypub_field="attributedTo" ) content = fields.HtmlField(blank=True, null=True) + raw_content = fields.HtmlField(blank=True, null=True) mention_users = fields.TagField("User", related_name="mention_user") mention_books = fields.TagField("Edition", related_name="mention_book") local = models.BooleanField(default=True) @@ -293,6 +294,7 @@ class Quotation(BookStatus): """like a review but without a rating and transient""" quote = fields.HtmlField() + raw_quote = fields.HtmlField(blank=True, null=True) position = models.IntegerField( validators=[MinValueValidator(0)], null=True, blank=True ) diff --git a/bookwyrm/templates/snippets/create_status/content_field.html b/bookwyrm/templates/snippets/create_status/content_field.html index 5102f207f..ea2849d92 100644 --- a/bookwyrm/templates/snippets/create_status/content_field.html +++ b/bookwyrm/templates/snippets/create_status/content_field.html @@ -16,5 +16,5 @@ draft: an existing Status object that is providing default values for input fiel placeholder="{{ placeholder }}" aria-label="{% if reply_parent %}{% trans 'Reply' %}{% else %}{% trans 'Content' %}{% endif %}" {% if not optional and type != "quotation" and type != "review" %}required{% endif %} ->{% if reply_parent %}{{ reply_parent|mentions:request.user }}{% endif %}{% if mention %}@{{ mention|username }} {% endif %}{{ draft.content|default:'' }} +>{% if reply_parent %}{{ reply_parent|mentions:request.user }}{% endif %}{% if mention %}@{{ mention|username }} {% endif %}{% firstof draft.raw_content draft.content '' %} diff --git a/bookwyrm/templates/snippets/create_status/quotation.html b/bookwyrm/templates/snippets/create_status/quotation.html index df48532fd..cf472c113 100644 --- a/bookwyrm/templates/snippets/create_status/quotation.html +++ b/bookwyrm/templates/snippets/create_status/quotation.html @@ -25,7 +25,7 @@ uuid: a unique identifier used to make html "id" attributes unique and clarify j placeholder="{% blocktrans with book_title=book.title %}An excerpt from '{{ book_title }}'{% endblocktrans %}" required {% if not draft %}data-cache-draft="id_quote_{{ book.id }}_{{ type }}"{% endif %} - >{{ draft.quote|default:'' }} + >{% firstof draft.raw_quote draft.quote '' %}
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index 4771ceb20..5f318d22e 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -76,6 +76,11 @@ class CreateStatus(View): return redirect(request.headers.get("Referer", "/")) status = form.save(commit=False) + # save the plain, unformatted version of the status for future editing + status.raw_content = status.content + if hasattr(status, "quote"): + status.raw_quote = status.quote + if not status.sensitive and status.content_warning: # the cw text field remains populated when you click "remove" status.content_warning = None From b9e6824360a5e78054fe177dc764cf563f3bc359 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 15 Oct 2021 10:07:29 -0700 Subject: [PATCH 2/6] Imrpove test names --- bookwyrm/tests/views/test_status.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index 93eedb74e..506569cc8 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -51,7 +51,7 @@ class StatusViews(TestCase): ) models.SiteSettings.objects.create() - def test_handle_status(self, *_): + def test_create_status(self, *_): """create a status""" view = views.CreateStatus.as_view() form = forms.CommentForm( @@ -73,7 +73,7 @@ class StatusViews(TestCase): self.assertEqual(status.book, self.book) self.assertIsNone(status.edited_date) - def test_handle_status_reply(self, *_): + def test_create_status_reply(self, *_): """create a status in reply to an existing status""" view = views.CreateStatus.as_view() user = models.User.objects.create_user( @@ -100,7 +100,7 @@ class StatusViews(TestCase): self.assertEqual(status.user, user) self.assertEqual(models.Notification.objects.get().user, self.local_user) - def test_handle_status_mentions(self, *_): + def test_create_status_mentions(self, *_): """@mention a user in a post""" view = views.CreateStatus.as_view() user = models.User.objects.create_user( @@ -130,7 +130,7 @@ class StatusViews(TestCase): status.content, f'

hi @rat

' ) - def test_handle_status_reply_with_mentions(self, *_): + def test_create_status_reply_with_mentions(self, *_): """reply to a post with an @mention'ed user""" view = views.CreateStatus.as_view() user = models.User.objects.create_user( @@ -297,7 +297,7 @@ http://www.fish.com/""" result = views.status.to_markdown(text) self.assertEqual(result, '

hi ' "is rad

") - def test_handle_delete_status(self, mock, *_): + def test_delete_status(self, mock, *_): """marks a status as deleted""" view = views.DeleteStatus.as_view() with patch("bookwyrm.activitystreams.add_status_task.delay"): @@ -315,7 +315,7 @@ http://www.fish.com/""" status.refresh_from_db() self.assertTrue(status.deleted) - def test_handle_delete_status_permission_denied(self, *_): + def test_delete_status_permission_denied(self, *_): """marks a status as deleted""" view = views.DeleteStatus.as_view() with patch("bookwyrm.activitystreams.add_status_task.delay"): @@ -330,7 +330,7 @@ http://www.fish.com/""" status.refresh_from_db() self.assertFalse(status.deleted) - def test_handle_delete_status_moderator(self, mock, *_): + def test_delete_status_moderator(self, mock, *_): """marks a status as deleted""" view = views.DeleteStatus.as_view() with patch("bookwyrm.activitystreams.add_status_task.delay"): From 60b910172de788775b44aa9f7d58ad674632c94f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 15 Oct 2021 10:09:34 -0700 Subject: [PATCH 3/6] Update migration --- bookwyrm/migrations/0110_auto_20211015_0128.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/migrations/0110_auto_20211015_0128.py b/bookwyrm/migrations/0110_auto_20211015_0128.py index aee378a36..c35e4281e 100644 --- a/bookwyrm/migrations/0110_auto_20211015_0128.py +++ b/bookwyrm/migrations/0110_auto_20211015_0128.py @@ -7,7 +7,7 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ("bookwyrm", "0109_status_edited"), + ("bookwyrm", "0109_status_edited_date"), ] operations = [ From e8f5678867133d48b856110b7e9ae560b56f1c47 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 15 Oct 2021 10:10:25 -0700 Subject: [PATCH 4/6] More test names --- bookwyrm/tests/views/test_status.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index 506569cc8..ea6e036c2 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -51,7 +51,7 @@ class StatusViews(TestCase): ) models.SiteSettings.objects.create() - def test_create_status(self, *_): + def test_create_status_comment(self, *_): """create a status""" view = views.CreateStatus.as_view() form = forms.CommentForm( @@ -378,7 +378,7 @@ http://www.fish.com/""" validate_html(result.render()) self.assertEqual(result.status_code, 200) - def test_create_status_edit_success(self, mock, *_): + def test_edit_status_success(self, mock, *_): """update an existing status""" status = models.Status.objects.create(content="status", user=self.local_user) self.assertIsNone(status.edited_date) @@ -403,7 +403,7 @@ http://www.fish.com/""" self.assertEqual(status.content, "

hi

") self.assertIsNotNone(status.edited_date) - def test_create_status_edit_permission_denied(self, *_): + def test_edit_status_permission_denied(self, *_): """update an existing status""" status = models.Status.objects.create(content="status", user=self.local_user) view = views.CreateStatus.as_view() From 61a0b50b9155485a48d7026879ab5fdcdb5a3a04 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 15 Oct 2021 10:10:38 -0700 Subject: [PATCH 5/6] Test raw version is saved --- bookwyrm/tests/views/test_status.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index ea6e036c2..db61b1528 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -68,6 +68,7 @@ class StatusViews(TestCase): view(request, "comment") status = models.Comment.objects.get() + self.assertEqual(status.raw_content, "hi") self.assertEqual(status.content, "

hi

") self.assertEqual(status.user, self.local_user) self.assertEqual(status.book, self.book) From bd0e4abd563abf13750e39ffb8c5eac270294b03 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 15 Oct 2021 10:36:46 -0700 Subject: [PATCH 6/6] Uses correct model field for raw values --- ..._auto_20211015_0128.py => 0110_auto_20211015_1734.py} | 9 ++++----- bookwyrm/models/status.py | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) rename bookwyrm/migrations/{0110_auto_20211015_0128.py => 0110_auto_20211015_1734.py} (57%) diff --git a/bookwyrm/migrations/0110_auto_20211015_0128.py b/bookwyrm/migrations/0110_auto_20211015_1734.py similarity index 57% rename from bookwyrm/migrations/0110_auto_20211015_0128.py rename to bookwyrm/migrations/0110_auto_20211015_1734.py index c35e4281e..ed7dd43c0 100644 --- a/bookwyrm/migrations/0110_auto_20211015_0128.py +++ b/bookwyrm/migrations/0110_auto_20211015_1734.py @@ -1,7 +1,6 @@ -# Generated by Django 3.2.5 on 2021-10-15 01:28 +# Generated by Django 3.2.5 on 2021-10-15 17:34 -import bookwyrm.models.fields -from django.db import migrations +from django.db import migrations, models class Migration(migrations.Migration): @@ -14,11 +13,11 @@ class Migration(migrations.Migration): migrations.AddField( model_name="quotation", name="raw_quote", - field=bookwyrm.models.fields.HtmlField(blank=True, null=True), + field=models.TextField(blank=True, null=True), ), migrations.AddField( model_name="status", name="raw_content", - field=bookwyrm.models.fields.HtmlField(blank=True, null=True), + field=models.TextField(blank=True, null=True), ), ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index d27efda71..a5657a4b6 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -31,7 +31,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): "User", on_delete=models.PROTECT, activitypub_field="attributedTo" ) content = fields.HtmlField(blank=True, null=True) - raw_content = fields.HtmlField(blank=True, null=True) + raw_content = models.TextField(blank=True, null=True) mention_users = fields.TagField("User", related_name="mention_user") mention_books = fields.TagField("Edition", related_name="mention_book") local = models.BooleanField(default=True) @@ -296,7 +296,7 @@ class Quotation(BookStatus): """like a review but without a rating and transient""" quote = fields.HtmlField() - raw_quote = fields.HtmlField(blank=True, null=True) + raw_quote = models.TextField(blank=True, null=True) position = models.IntegerField( validators=[MinValueValidator(0)], null=True, blank=True )