mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 19:11:09 +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"]
|
||||
|
||||
|
||||
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 Meta:
|
||||
model = models.User
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<h1>{% trans "Compose status" %}</h1>
|
||||
</header>
|
||||
|
||||
{% with 0|uuid as uuid %}
|
||||
<div class="box columns">
|
||||
{% if book %}
|
||||
<div class="column is-one-third">
|
||||
|
@ -18,13 +19,13 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
<div class="column is-two-thirds">
|
||||
{% if not form %}
|
||||
{% if not draft %}
|
||||
{% include 'snippets/create_status.html' %}
|
||||
{% else %}
|
||||
{% include 'snippets/create_status_form.html' %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ form.ap_p }}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
{% 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>
|
||||
<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>
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="{{ book.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' %}
|
||||
<div class="control">
|
||||
<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>
|
||||
{% endif %}
|
||||
<div class="control">
|
||||
|
@ -29,9 +29,9 @@
|
|||
<legend class="is-sr-only">{% trans "Rating" %}</legend>
|
||||
<div class="field is-grouped stars form-rate-stars">
|
||||
<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 %}
|
||||
<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 }}">
|
||||
<span class="is-sr-only">{{ forloop.counter }} star{{ forloop.counter | pluralize }}</span>
|
||||
</label>
|
||||
|
@ -41,17 +41,17 @@
|
|||
{% endif %}
|
||||
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
</div>
|
||||
{% if type == 'quotation' %}
|
||||
<div class="control">
|
||||
<label class="label" for="id_content_quote-{{ book.id }}">{% trans "Comment" %}:</label>
|
||||
{% 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>
|
||||
{% elif type == 'comment' %}
|
||||
<div class="control">
|
||||
|
@ -64,12 +64,12 @@
|
|||
<label class="label" for="progress-{{ uuid }}">{% trans "Progress:" %}</label>
|
||||
<div class="field has-addons mb-0">
|
||||
<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 class="control select">
|
||||
<select name="progress_mode" aria-label="Progress mode">
|
||||
<option value="PG" {% if readthrough.progress_mode == 'PG' %}selected{% endif %}>{% trans "pages" %}</option>
|
||||
<option value="PCT" {% if readthrough.progress_mode == 'PCT' %}selected{% endif %}>{% trans "percent" %}</option>
|
||||
<option value="PG" {% if draft.progress_mode == 'PG' or readthrough.progress_mode == 'PG' %}selected{% endif %}>{% trans "pages" %}</option>
|
||||
<option value="PCT" {% if draft.progress_mode == 'PCT' or readthrough.progress_mode == 'PCT' %}selected{% endif %}>{% trans "percent" %}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -81,21 +81,26 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
{% 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 #}
|
||||
<div class="columns pt-1">
|
||||
<div class="field has-addons column">
|
||||
<div class="control">
|
||||
{% 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 class="control">
|
||||
{% if type == 'direct' %}
|
||||
<input type="hidden" name="privacy" value="direct">
|
||||
<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 %}
|
||||
{% include 'snippets/privacy_select.html' with current=reply_parent.privacy %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
</button>
|
||||
</form>
|
||||
</li>
|
||||
{% if status.status_type != 'GeneratedNote' %}
|
||||
<li role="menuitem">
|
||||
<form class="dropdown-item pt-0 pb-0" name="delete-{{status.id}}" action="{% url 'redraft' status.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
|
@ -27,6 +28,7 @@
|
|||
</button>
|
||||
</form>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{# things you can do to other people's statuses #}
|
||||
<li role="menuitem">
|
||||
|
|
|
@ -75,7 +75,7 @@ class CreateStatus(View):
|
|||
# update a readthorugh, if needed
|
||||
edit_readthrough(request)
|
||||
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
return redirect("/")
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
|
@ -101,16 +101,24 @@ class DeleteAndRedraft(View):
|
|||
|
||||
def post(self, request, status_id):
|
||||
""" delete and tombstone a status """
|
||||
status = get_object_or_404(models.Status, 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"):
|
||||
status = get_object_or_404(
|
||||
models.Status.objects.select_subclasses(), id=status_id
|
||||
)
|
||||
if isinstance(status, models.GeneratedNote):
|
||||
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"):
|
||||
data["book"] = status.book
|
||||
elif status.mention_books:
|
||||
data["book"] = status.mention_books.first()
|
||||
|
||||
# perform deletion
|
||||
status.delete()
|
||||
|
|
Loading…
Reference in a new issue