1
0
mirror of https://gitlab.com/brutaldon/brutaldon.git synced 2024-12-04 14:46:24 -05:00

Add basic re-drafting without image support

This commit is contained in:
Jason McBrayer 2018-08-23 20:58:07 -04:00
parent fb6e1d6b7a
commit 9797b6f7c2
5 changed files with 101 additions and 0 deletions

View File

@ -2,6 +2,8 @@
{% if reply %}
<form method="post" id="post-form" action="{% url "reply" toot.id %}" enctype="multipart/form-data">
{% elif redraft %}
<form method="post" id="post-form" action="{% url "redraft" toot.id %}" enctype="multipart/form-data">
{% else %}
<form id="post-form" method="post" action="{% url "toot" %}" enctype="multipart/form-data">
{% endif %}

View File

@ -0,0 +1,42 @@
{% extends "base.html" %}
{% load humanize %}
{% load static %}
{% block title %}
Brutaldon ({{ own_acct.username }}) - reply
{% endblock %}
{% block page_scripts %}
<script src="{% static 'js/mousetrap.min.js' %}" type="application/javascript"></script>
{% endblock %}
{% block content %}
<h1 class="title">Redraft</h1>
{% include "main/toot_partial.html" with toot=toot active=True %}
<hr class="is-hidden">
<div class="notification">
<p>
Submitting this form will <em>post</em> this replacement toot, and
<em class="error">delete</em> the original toot. The replacement toot will not
have any favs, boosts, or replies that the original toot had.
Currently, media attachments must be re-uploaded. Sorry, working on it.
</p>
</div>
<div class="box">
{% include "main/post_partial.html" %}
</div>
{% endblock %}
{% block page_scripts_inline %}
<script type="application/javascript">
document.addEventListener('DOMContentLoaded', function () {
Mousetrap.bind('ctrl+enter', function(e) {
var form = document.querySelector('#post-form');
form.submit();
return true;
});
});
</script>
{% endblock %}

View File

@ -118,6 +118,9 @@
</div>
<div class="level-right">
{% if toot.account.acct == own_acct.acct %}
<a class="level-item" href="{% url "redraft" toot.id %}">
redraft
</a>
<a class="level-item" href="{% url "delete" toot.id %}">
delete
</a>

View File

@ -47,6 +47,7 @@ urlpatterns = [
path('toot/<mention>', views.toot, name='toot'),
path('toot', views.toot, name="toot"),
path('reply/<int:id>', views.reply, name='reply'),
path('redraft/<int:id>', views.redraft, name='redraft'),
path('fav/<int:id>', views.fav, name='fav'),
path('boost/<int:id>', views.boost, name='boost'),
path('delete/<int:id>', views.delete, name='delete'),

View File

@ -425,6 +425,59 @@ def toot(request, mention=None):
else:
return redirect(toot)
@br_login_required
def redraft(request, id):
if request.method == 'GET':
mastodon = get_mastodon(request)
toot = mastodon.status(id)
form = PostForm({'status': toot.content,
'visibility': toot.visibility,
'spoiler_text': toot.spoiler_text,
'media_text_1': safe_get_attachment(toot, 0),
'media_text_2': safe_get_attachment(toot, 1),
'media_text_3': safe_get_attachment(toot, 2),
'media_text_4': safe_get_attachment(toot, 3),
})
return render(request, 'main/redraft.html',
{'toot': toot, 'form': form, 'redraft':True,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)})
elif request.method == 'POST':
form = PostForm(request.POST, request.FILES)
mastodon = get_mastodon(request)
toot = mastodon.status(id)
if form.is_valid():
media_objects = toot.media_attachments
mastodon.status_post(status=form.cleaned_data['status'],
visibility=form.cleaned_data['visibility'],
spoiler_text=form.cleaned_data['spoiler_text'],
media_ids=media_objects,
in_reply_to_id=toot.in_reply_to_id)
mastodon.status_delete(id)
return redirect(home)
else:
return render(request, 'main/redraft.html',
{'toot': toot, 'form': form, 'redraft': True,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)})
else:
return redirect(redraft, id)
def safe_get_attachment(toot, index):
"""Get an attachment from a toot, without crashing if it isn't there."""
try:
return toot.media_attachments[index]
except IndexError:
return {
'id': "",
'type': 'unknown',
'url': '',
'remote_url': '',
'preview_url': "",
'text_url': "",
}
@br_login_required
def reply(request, id):
if request.method == 'GET':