Add replies

This commit is contained in:
Jason McBrayer 2018-04-30 14:31:59 -04:00
parent 2f448242f8
commit d6fe609b29
6 changed files with 60 additions and 6 deletions

View File

@ -1,6 +1,10 @@
{% load widget_tweaks %} {% load widget_tweaks %}
{% if reply %}
<form method="post" action="{% url "reply" toot.id %}">
{% else %}
<form method="post" action="{% url "toot" %}"> <form method="post" action="{% url "toot" %}">
{% endif %}
{% csrf_token %} {% csrf_token %}
<div class="field" > <div class="field" >
@ -21,10 +25,6 @@
</div> </div>
</div> </div>
</div> </div>
{% if form.errors %}
<div> {{ form.errors }} </div>
{% endif %}
<input type="submit" class="button is-primary" <input type="submit" class="button is-primary"

View File

@ -0,0 +1,24 @@
{% extends "base.html" %}
{% load humanize %}
{% block title %}
Brutaldon - reply
{% endblock %}
{% block content %}
<h1 class="title">Thread</h1>
{% for ancestor in context.ancestors %}
<div class="box">
{% include "main/toot_partial.html" with toot=ancestor %}
</div>
<hr class="is-hidden">
{% endfor %}
<div class="box active_context">
{% include "main/toot_partial.html" with toot=toot %}
</div>
<hr class="is-hidden">
<div class="box">
{% include "main/post_partial.html" %}
</div>
{% endblock %}

View File

@ -63,7 +63,7 @@
<p class="is-hidden"></p> <p class="is-hidden"></p>
<nav class="level is-mobile"> <nav class="level is-mobile">
<div class="level-left"> <div class="level-left">
<a class="level-item"> <a class="level-item" href="{% url "reply" toot.id %}">
<span class="icon is-small"><i class="fa fa-reply"> <span class="icon is-small"><i class="fa fa-reply">
<span class="is-invisible">Reply</span> <span class="is-invisible">Reply</span>
</i></span> </i></span>

View File

@ -29,5 +29,6 @@ urlpatterns = [
path('settings', views.settings, name='settings'), path('settings', views.settings, name='settings'),
path('thread/<int:id>', views.thread, name='thread'), path('thread/<int:id>', views.thread, name='thread'),
path('toot', views.toot, name="toot"), path('toot', views.toot, name="toot"),
path('reply/<int:id>', views.reply, name='reply'),
path('', views.home), path('', views.home),
] ]

View File

@ -165,3 +165,32 @@ def toot(request):
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
else: else:
return redirect(toot) return redirect(toot)
def reply(request, id):
if request.method == 'GET':
mastodon = get_mastodon(request)
toot = mastodon.status(id)
context = mastodon.status_context(id)
initial_text = '@' + toot.account.acct + " "
for mention in toot.mentions:
initial_text.append('@' + mention.acct + " ")
form = PostForm({'status': initial_text})
return render(request, 'main/reply.html',
{'context': context, 'toot': toot, 'form': form, 'reply':True,
'fullbrutalism': fullbrutalism_p(request)})
elif request.method == 'POST':
form = PostForm(request.POST, request.FILES)
if form.is_valid():
# create media objects
mastodon = get_mastodon(request)
mastodon.status_post(status=form.cleaned_data['status'],
visibility=form.cleaned_data['visibility'],
spoiler_text=form.cleaned_data['spoiler_text'],
in_reply_to_id=id)
return redirect(thread, id)
else:
return render(request, 'main/reply.html',
{'context': context, 'toot': toot, 'form': form, 'reply': True,
'fullbrutalism': fullbrutalism_p(request)})
else:
return redirect(reply, id)