mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-16 13:16:33 +00:00
Merge pull request #1536 from bookwyrm-social/markdown
Edit posts in original markdown syntax
This commit is contained in:
commit
72a8f34a8f
6 changed files with 42 additions and 11 deletions
23
bookwyrm/migrations/0110_auto_20211015_1734.py
Normal file
23
bookwyrm/migrations/0110_auto_20211015_1734.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.2.5 on 2021-10-15 17:34
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0109_status_edited_date"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="quotation",
|
||||
name="raw_quote",
|
||||
field=models.TextField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="status",
|
||||
name="raw_content",
|
||||
field=models.TextField(blank=True, null=True),
|
||||
),
|
||||
]
|
|
@ -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 = 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)
|
||||
|
@ -295,6 +296,7 @@ class Quotation(BookStatus):
|
|||
"""like a review but without a rating and transient"""
|
||||
|
||||
quote = fields.HtmlField()
|
||||
raw_quote = models.TextField(blank=True, null=True)
|
||||
position = models.IntegerField(
|
||||
validators=[MinValueValidator(0)], null=True, blank=True
|
||||
)
|
||||
|
|
|
@ -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:'' }}</textarea>
|
||||
>{% if reply_parent %}{{ reply_parent|mentions:request.user }}{% endif %}{% if mention %}@{{ mention|username }} {% endif %}{% firstof draft.raw_content draft.content '' %}</textarea>
|
||||
|
||||
|
|
|
@ -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:'' }}</textarea>
|
||||
>{% firstof draft.raw_quote draft.quote '' %}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
|
|
|
@ -51,7 +51,7 @@ class StatusViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_handle_status(self, *_):
|
||||
def test_create_status_comment(self, *_):
|
||||
"""create a status"""
|
||||
view = views.CreateStatus.as_view()
|
||||
form = forms.CommentForm(
|
||||
|
@ -68,12 +68,13 @@ class StatusViews(TestCase):
|
|||
view(request, "comment")
|
||||
|
||||
status = models.Comment.objects.get()
|
||||
self.assertEqual(status.raw_content, "hi")
|
||||
self.assertEqual(status.content, "<p>hi</p>")
|
||||
self.assertEqual(status.user, self.local_user)
|
||||
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 +101,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 +131,7 @@ class StatusViews(TestCase):
|
|||
status.content, f'<p>hi <a href="{user.remote_id}">@rat</a></p>'
|
||||
)
|
||||
|
||||
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 +298,7 @@ http://www.fish.com/"""
|
|||
result = views.status.to_markdown(text)
|
||||
self.assertEqual(result, '<p><a href="http://fish.com">hi</a> ' "is rad</p>")
|
||||
|
||||
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 +316,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 +331,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"):
|
||||
|
@ -378,7 +379,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 +404,7 @@ http://www.fish.com/"""
|
|||
self.assertEqual(status.content, "<p>hi</p>")
|
||||
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()
|
||||
|
|
|
@ -79,6 +79,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
|
||||
|
|
Loading…
Reference in a new issue