mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
Populate redraft form
This commit is contained in:
parent
6ed74e6f60
commit
ffb7f8f7ce
6 changed files with 46 additions and 37 deletions
|
@ -121,20 +121,6 @@ class StatusForm(CustomForm):
|
||||||
fields = ["user", "content", "content_warning", "sensitive", "privacy"]
|
fields = ["user", "content", "content_warning", "sensitive", "privacy"]
|
||||||
|
|
||||||
|
|
||||||
def get_form_from_status(status):
|
|
||||||
""" form-ify a status (for delete and redraft) """
|
|
||||||
if isinstance(status, models.Review):
|
|
||||||
return ReviewForm(instance=status)
|
|
||||||
if isinstance(status, models.Comment):
|
|
||||||
return CommentForm(instance=status)
|
|
||||||
if isinstance(status, models.Quotation):
|
|
||||||
return QuotationForm(instance=status)
|
|
||||||
if status.reply_parent:
|
|
||||||
return ReplyForm(instance=status)
|
|
||||||
else:
|
|
||||||
return StatusForm(instance=status)
|
|
||||||
|
|
||||||
|
|
||||||
class EditUserForm(CustomForm):
|
class EditUserForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.User
|
model = models.User
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<h1>{% trans "Compose status" %}</h1>
|
<h1>{% trans "Compose status" %}</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
{% with 0|uuid as uuid %}
|
||||||
<div class="box columns">
|
<div class="box columns">
|
||||||
{% if book %}
|
{% if book %}
|
||||||
<div class="column is-one-third">
|
<div class="column is-one-third">
|
||||||
|
@ -18,13 +19,13 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="column is-two-thirds">
|
<div class="column is-two-thirds">
|
||||||
{% if not form %}
|
{% if not draft %}
|
||||||
{% include 'snippets/create_status.html' %}
|
{% include 'snippets/create_status.html' %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% include 'snippets/create_status_form.html' %}
|
{% include 'snippets/create_status_form.html' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{ form.ap_p }}
|
||||||
|
{% endwith %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<div class="control{% if not parent_status.content_warning %} hidden{% endif %}" id="spoilers-{{ uuid }}">
|
<div class="control{% if not parent_status.content_warning and not draft.content_warning %} hidden{% endif %}" id="spoilers-{{ uuid }}">
|
||||||
<label class="is-sr-only" for="id_content_warning-{{ uuid }}">{% trans "Spoiler alert:" %}</label>
|
<label class="is-sr-only" for="id_content_warning-{{ uuid }}">{% trans "Spoiler alert:" %}</label>
|
||||||
<input type="text" name="content_warning" maxlength="255" class="input" id="id_content_warning-{{ uuid }}" placeholder="{% trans 'Spoilers ahead!' %}"{% if parent_status.content_warning %} value="{{ parent_status.content_warning }}"{% endif %}>
|
<input
|
||||||
|
type="text"
|
||||||
|
name="content_warning"
|
||||||
|
maxlength="255"
|
||||||
|
class="input"
|
||||||
|
id="id_content_warning-{{ uuid }}"
|
||||||
|
placeholder="{% trans 'Spoilers ahead!' %}"
|
||||||
|
value="{% firstof draft.content_warning parent_status.content_warning '' %}">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="book" value="{{ book.id }}">
|
<input type="hidden" name="book" value="{{ book.id }}">
|
||||||
<input type="hidden" name="user" value="{{ request.user.id }}">
|
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||||
<input type="hidden" name="reply_parent" value="{{ reply_parent.id }}">
|
<input type="hidden" name="reply_parent" value="{% firstof draft.reply_parent.id reply_parent.id %}">
|
||||||
{% if type == 'review' %}
|
{% if type == 'review' %}
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<label class="label" for="id_name_{{ book.id }}_{{ type }}">{% trans "Title" %}:</label>
|
<label class="label" for="id_name_{{ book.id }}_{{ type }}">{% trans "Title" %}:</label>
|
||||||
<input type="text" name="name" maxlength="255" class="input" required="" id="id_name_{{ book.id }}_{{ type }}" placeholder="My {{ type }} of '{{ book.title }}'">
|
<input type="text" name="name" maxlength="255" class="input" required="" id="id_name_{{ book.id }}_{{ type }}" placeholder="My {{ type }} of '{{ book.title }}'" value="{% firstof draft.name ''%}">
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
@ -29,9 +29,9 @@
|
||||||
<legend class="is-sr-only">{% trans "Rating" %}</legend>
|
<legend class="is-sr-only">{% trans "Rating" %}</legend>
|
||||||
<div class="field is-grouped stars form-rate-stars">
|
<div class="field is-grouped stars form-rate-stars">
|
||||||
<label class="is-sr-only" for="no-rating-{{ book.id }}">{% trans "No rating" %}</label>
|
<label class="is-sr-only" for="no-rating-{{ book.id }}">{% trans "No rating" %}</label>
|
||||||
<input class="is-sr-only" type="radio" name="rating" value="" id="no-rating-{{ book.id }}" checked>
|
<input class="is-sr-only" type="radio" name="rating" value="" id="no-rating-{{ book.id }}" {% if not draft or not draft.rating %}checked{% endif %}>
|
||||||
{% for i in '12345'|make_list %}
|
{% for i in '12345'|make_list %}
|
||||||
<input class="is-sr-only" id="book{{book.id}}-star-{{ forloop.counter }}" type="radio" name="rating" value="{{ forloop.counter }}">
|
<input class="is-sr-only" id="book{{book.id}}-star-{{ forloop.counter }}" type="radio" name="rating" value="{{ forloop.counter }}" {% if draft and draft.rating == forloop.counter %}checked{% endif %}>
|
||||||
<label class="icon icon-star-empty" for="book{{book.id}}-star-{{ forloop.counter }}">
|
<label class="icon icon-star-empty" for="book{{book.id}}-star-{{ forloop.counter }}">
|
||||||
<span class="is-sr-only">{{ forloop.counter }} star{{ forloop.counter | pluralize }}</span>
|
<span class="is-sr-only">{{ forloop.counter }} star{{ forloop.counter | pluralize }}</span>
|
||||||
</label>
|
</label>
|
||||||
|
@ -41,17 +41,17 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if type == 'quotation' %}
|
{% if type == 'quotation' %}
|
||||||
<textarea name="quote" class="textarea" id="id_quote_{{ book.id }}_{{ type }}" placeholder="{{ placeholder }}" required></textarea>
|
<textarea name="quote" class="textarea" id="id_quote_{{ book.id }}_{{ type }}" placeholder="{{ placeholder }}" required>{{ draft.quote|default:'' }}</textarea>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% include 'snippets/content_warning_field.html' with parent_status=status %}
|
{% include 'snippets/content_warning_field.html' with parent_status=status %}
|
||||||
<textarea name="content" class="textarea" id="id_content_{{ type }}-{{ book.id }}{{reply_parent.id}}" placeholder="{{ placeholder }}" {% if type == 'reply' %} aria-label="Reply"{% endif %} required>{% if reply_parent %}{{ reply_parent|mentions:request.user }}{% endif %}{% if mentions %}@{{ mentions|username }} {% endif %}</textarea>
|
<textarea name="content" class="textarea" id="id_content_{{ type }}-{{ book.id }}{{reply_parent.id}}" placeholder="{{ placeholder }}" {% if type == 'reply' %} aria-label="Reply"{% endif %} required>{% if reply_parent %}{{ reply_parent|mentions:request.user }}{% endif %}{% if mentions %}@{{ mentions|username }} {% endif %}{{ draft.content|default:'' }}</textarea>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if type == 'quotation' %}
|
{% if type == 'quotation' %}
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<label class="label" for="id_content_quote-{{ book.id }}">{% trans "Comment" %}:</label>
|
<label class="label" for="id_content_quote-{{ book.id }}">{% trans "Comment" %}:</label>
|
||||||
{% include 'snippets/content_warning_field.html' with parent_status=status %}
|
{% include 'snippets/content_warning_field.html' with parent_status=status %}
|
||||||
<textarea name="content" class="textarea is-small" id="id_content_quote-{{ book.id }}"></textarea>
|
<textarea name="content" class="textarea is-small" id="id_content_quote-{{ book.id }}">{{ draft.content|default:'' }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
{% elif type == 'comment' %}
|
{% elif type == 'comment' %}
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
@ -64,12 +64,12 @@
|
||||||
<label class="label" for="progress-{{ uuid }}">{% trans "Progress:" %}</label>
|
<label class="label" for="progress-{{ uuid }}">{% trans "Progress:" %}</label>
|
||||||
<div class="field has-addons mb-0">
|
<div class="field has-addons mb-0">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input aria-label="{% if readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}" class="input" type="number" min="0" name="progress" size="3" value="{{ readthrough.progress|default:'' }}" id="progress-{{ uuid }}">
|
<input aria-label="{% if draft.progress_mode == 'PG' or readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}" class="input" type="number" min="0" name="progress" size="3" value="{% firstof draft.progress readthrough.progress '' %}" id="progress-{{ uuid }}">
|
||||||
</div>
|
</div>
|
||||||
<div class="control select">
|
<div class="control select">
|
||||||
<select name="progress_mode" aria-label="Progress mode">
|
<select name="progress_mode" aria-label="Progress mode">
|
||||||
<option value="PG" {% if readthrough.progress_mode == 'PG' %}selected{% endif %}>{% trans "pages" %}</option>
|
<option value="PG" {% if draft.progress_mode == 'PG' or readthrough.progress_mode == 'PG' %}selected{% endif %}>{% trans "pages" %}</option>
|
||||||
<option value="PCT" {% if readthrough.progress_mode == 'PCT' %}selected{% endif %}>{% trans "percent" %}</option>
|
<option value="PCT" {% if draft.progress_mode == 'PCT' or readthrough.progress_mode == 'PCT' %}selected{% endif %}>{% trans "percent" %}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -81,21 +81,26 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<input type="checkbox" class="hidden" name="sensitive" id="id_show_spoilers-{{ uuid }}" {% if status.content_warning %}checked{% endif %} aria-hidden="true">
|
<input type="checkbox" class="hidden" name="sensitive" id="id_show_spoilers-{{ uuid }}" {% if draft.content_warning or status.content_warning %}checked{% endif %} aria-hidden="{% if draft.content_warning or status.content_warning %}true{% else %}false{% endif %}">
|
||||||
{# bottom bar #}
|
{# bottom bar #}
|
||||||
<div class="columns pt-1">
|
<div class="columns pt-1">
|
||||||
<div class="field has-addons column">
|
<div class="field has-addons column">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
{% trans "Include spoiler alert" as button_text %}
|
{% trans "Include spoiler alert" as button_text %}
|
||||||
{% include 'snippets/toggle/toggle_button.html' with text=button_text icon="warning is-size-4" controls_text="spoilers" controls_uid=uuid focus="id_content_warning" checkbox="id_show_spoilers" class="toggle-button" pressed=status.content_warning %}
|
{% firstof draft.content_warning status.content_warning as pressed %}
|
||||||
|
{% include 'snippets/toggle/toggle_button.html' with text=button_text icon="warning is-size-4" controls_text="spoilers" controls_uid=uuid focus="id_content_warning" checkbox="id_show_spoilers" class="toggle-button" pressed=pressed %}
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
{% if type == 'direct' %}
|
{% if type == 'direct' %}
|
||||||
<input type="hidden" name="privacy" value="direct">
|
<input type="hidden" name="privacy" value="direct">
|
||||||
<button type="button" class="button" aria-label="Privacy" disabled>{% trans "Private" %}</button>
|
<button type="button" class="button" aria-label="Privacy" disabled>{% trans "Private" %}</button>
|
||||||
|
{% else %}
|
||||||
|
{% if draft %}
|
||||||
|
{% include 'snippets/privacy_select.html' with current=draft.privacy %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% include 'snippets/privacy_select.html' with current=reply_parent.privacy %}
|
{% include 'snippets/privacy_select.html' with current=reply_parent.privacy %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-narrow">
|
<div class="column is-narrow">
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
|
{% if status.status_type != 'GeneratedNote' %}
|
||||||
<li role="menuitem">
|
<li role="menuitem">
|
||||||
<form class="dropdown-item pt-0 pb-0" name="delete-{{status.id}}" action="{% url 'redraft' status.id %}" method="post">
|
<form class="dropdown-item pt-0 pb-0" name="delete-{{status.id}}" action="{% url 'redraft' status.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -27,6 +28,7 @@
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{# things you can do to other people's statuses #}
|
{# things you can do to other people's statuses #}
|
||||||
<li role="menuitem">
|
<li role="menuitem">
|
||||||
|
|
|
@ -75,7 +75,7 @@ class CreateStatus(View):
|
||||||
# update a readthorugh, if needed
|
# update a readthorugh, if needed
|
||||||
edit_readthrough(request)
|
edit_readthrough(request)
|
||||||
|
|
||||||
return redirect(request.headers.get("Referer", "/"))
|
return redirect("/")
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name="dispatch")
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@ -101,16 +101,24 @@ class DeleteAndRedraft(View):
|
||||||
|
|
||||||
def post(self, request, status_id):
|
def post(self, request, status_id):
|
||||||
""" delete and tombstone a status """
|
""" delete and tombstone a status """
|
||||||
status = get_object_or_404(models.Status, id=status_id)
|
status = get_object_or_404(
|
||||||
|
models.Status.objects.select_subclasses(), id=status_id
|
||||||
# don't let people delete other people's statuses
|
)
|
||||||
if status.user != request.user and not request.user.has_perm("moderate_post"):
|
if isinstance(status, models.GeneratedNote):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
# don't let people redraft other people's statuses
|
||||||
|
if status.user != request.user:
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
data = {"form": forms.get_form_from_status(status)}
|
data = {
|
||||||
|
"draft": status,
|
||||||
|
"type": status.status_type.lower(),
|
||||||
|
}
|
||||||
if hasattr(status, "book"):
|
if hasattr(status, "book"):
|
||||||
data["book"] = status.book
|
data["book"] = status.book
|
||||||
|
elif status.mention_books:
|
||||||
|
data["book"] = status.mention_books.first()
|
||||||
|
|
||||||
# perform deletion
|
# perform deletion
|
||||||
status.delete()
|
status.delete()
|
||||||
|
|
Loading…
Reference in a new issue