mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Adds model-to-form helper for statuses
This commit is contained in:
parent
4cf9bca5aa
commit
2a4fc8fb9a
3 changed files with 24 additions and 2 deletions
|
@ -121,6 +121,20 @@ 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
|
||||||
|
|
|
@ -19,6 +19,14 @@
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
|
<li role="menuitem">
|
||||||
|
<form class="dropdown-item pt-0 pb-0" name="delete-{{status.id}}" action="{% url 'redraft' status.id %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="button is-danger is-light is-fullwidth is-small" type="submit">
|
||||||
|
{% trans "Delete & re-draft" %}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
{% 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">
|
||||||
|
|
|
@ -107,8 +107,8 @@ class DeleteAndRedraft(View):
|
||||||
if status.user != request.user and not request.user.has_perm("moderate_post"):
|
if status.user != request.user and not request.user.has_perm("moderate_post"):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
# TODO: get the correct form (maybe a generic form)
|
|
||||||
data = {"form": forms.StatusForm(instance=status)}
|
data = {"form": forms.get_form_from_status(status)}
|
||||||
if hasattr(status, "book"):
|
if hasattr(status, "book"):
|
||||||
data["book"] = status.book
|
data["book"] = status.book
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue