diff --git a/brutaldon/templates/main/post_partial.html b/brutaldon/templates/main/post_partial.html index d3fcf93..b8589cf 100644 --- a/brutaldon/templates/main/post_partial.html +++ b/brutaldon/templates/main/post_partial.html @@ -2,6 +2,8 @@ {% if reply %}
+{% elif redraft %} + {% else %} {% endif %} diff --git a/brutaldon/templates/main/redraft.html b/brutaldon/templates/main/redraft.html new file mode 100644 index 0000000..30ee1a1 --- /dev/null +++ b/brutaldon/templates/main/redraft.html @@ -0,0 +1,42 @@ +{% extends "base.html" %} +{% load humanize %} +{% load static %} + +{% block title %} +Brutaldon ({{ own_acct.username }}) - reply +{% endblock %} + +{% block page_scripts %} + +{% endblock %} + +{% block content %} +

Redraft

+ {% include "main/toot_partial.html" with toot=toot active=True %} + +
+

+ Submitting this form will post this replacement toot, and + delete 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. +

+
+ +
+ {% include "main/post_partial.html" %} +
+ +{% endblock %} + +{% block page_scripts_inline %} + +{% endblock %} diff --git a/brutaldon/templates/main/toot_partial.html b/brutaldon/templates/main/toot_partial.html index 863ebbb..d8091a2 100644 --- a/brutaldon/templates/main/toot_partial.html +++ b/brutaldon/templates/main/toot_partial.html @@ -118,6 +118,9 @@
{% if toot.account.acct == own_acct.acct %} + + redraft + delete diff --git a/brutaldon/urls.py b/brutaldon/urls.py index ee775e9..2796065 100644 --- a/brutaldon/urls.py +++ b/brutaldon/urls.py @@ -47,6 +47,7 @@ urlpatterns = [ path('toot/', views.toot, name='toot'), path('toot', views.toot, name="toot"), path('reply/', views.reply, name='reply'), + path('redraft/', views.redraft, name='redraft'), path('fav/', views.fav, name='fav'), path('boost/', views.boost, name='boost'), path('delete/', views.delete, name='delete'), diff --git a/brutaldon/views.py b/brutaldon/views.py index cd40a18..d866bbb 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -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':