Edit posts in original markdown syntax

This commit is contained in:
Mouse Reeve 2021-10-14 18:34:26 -07:00
parent 01911d3b23
commit af567ba05e
5 changed files with 33 additions and 2 deletions

View file

@ -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),
),
]

View file

@ -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
)

View file

@ -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>

View file

@ -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">

View file

@ -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