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

Allow deleting your own toots

This commit is contained in:
Jason McBrayer 2018-05-22 09:41:11 -04:00
parent ac02b941c0
commit 2895bae6bc
5 changed files with 56 additions and 2 deletions

View File

@ -1,7 +1,6 @@
from django import forms
PRIVACY_CHOICES = (('default', 'Default'),
('public', 'Public'),
PRIVACY_CHOICES = (('public', 'Public'),
('unlisted', 'Unlisted'),
('private', 'Private'),
('direct', 'Direct'))

View File

@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block title %} Brutaldon - confirm delete {% endblock %}
{% block content %}
<h1 class="title">Delete that toot?</h1>
<div class="box">
{% include "main/toot_partial.html" with toot=toot %}
</div>
<form method="POST" action="{% url "delete" toot.id %}">
{% csrf_token %}
<div class="level is-mobile">
<div class="level-left">
<div class="level-item">
<input class="button" type="submit" name="cancel" value="Cancel">
</div>
</div>
<div class="level-right">
<div class="level-item">
<input class="button is-primary" type="submit" name="delete"
value="Delete">
</div>
</div>
</div>
</form>
{% endblock %}

View File

@ -112,6 +112,11 @@
</div>
</div>
<div class="level-right">
{% if toot.account.acct == own_username %}
<a class="level-item" href="{% url "delete" toot.id %}">
delete
</a>
{% endif %}
<span class="level-item">
{{ toot.visibility }}
</span>

View File

@ -42,5 +42,6 @@ urlpatterns = [
path('reply/<int:id>', views.reply, name='reply'),
path('fav/<int:id>', views.fav, name='fav'),
path('boost/<int:id>', views.boost, name='boost'),
path('delete/<int:id>', views.delete, name='delete'),
path('', views.home),
]

View File

@ -71,6 +71,7 @@ def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_
return render(request, 'main/%s_timeline.html' % timeline,
{'toots': data, 'form': form, 'timeline': timeline,
'timeline_name': timeline_name,
'own_username': request.session['user'].acct,
'fullbrutalism': fullbrutalism_p(request),
'prev': prev, 'next': next})
@ -91,6 +92,7 @@ def tag(request, tag):
data = mastodon.timeline_hashtag(tag)
return render(request, 'main/timeline.html',
{'toots': data, 'timeline': '#'+tag,
'own_username': request.session['user'].acct,
'fullbrutalism': fullbrutalism_p(request)})
@never_cache
@ -229,6 +231,7 @@ def note(request):
notes = mastodon.notifications()
return render(request, 'main/notifications.html',
{'notes': notes,'timeline': 'Notifications',
'own_username': request.session['user'].acct,
'fullbrutalism': fullbrutalism_p(request)})
def thread(request, id):
@ -237,6 +240,7 @@ def thread(request, id):
toot = mastodon.status(id)
return render(request, 'main/thread.html',
{'context': context, 'toot': toot,
'own_username': request.session['user'].acct,
'fullbrutalism': fullbrutalism_p(request)})
def user(request, username):
@ -248,6 +252,7 @@ def user(request, username):
data = mastodon.account_statuses(user_dict.id)
return render(request, 'main/user.html',
{'toots': data, 'user': user_dict,
'own_username': request.session['user'].acct,
'fullbrutalism': fullbrutalism_p(request)})
@ -315,6 +320,7 @@ def reply(request, id):
'spoiler_text': toot.spoiler_text})
return render(request, 'main/reply.html',
{'context': context, 'toot': toot, 'form': form, 'reply':True,
'own_username': request.session['user'].acct,
'fullbrutalism': fullbrutalism_p(request)})
elif request.method == 'POST':
form = PostForm(request.POST, request.FILES)
@ -341,6 +347,7 @@ def reply(request, id):
context = mastodon.status_context(id)
return render(request, 'main/reply.html',
{'context': context, 'toot': toot, 'form': form, 'reply': True,
'own_username': request.session['user'].acct,
'fullbrutalism': fullbrutalism_p(request)})
else:
return redirect(reply, id)
@ -376,3 +383,18 @@ def boost(request, id):
return render(request, 'main/boost.html',
{"toot": toot, 'confirm_page': True,
"fullbrutalism": fullbrutalism_p(request)})
@never_cache
def delete(request, id):
mastodon = get_mastodon(request)
toot = mastodon.status(id)
if request.method == 'POST':
if toot.account.acct != request.session['user'].acct:
return redirect('home')
if not request.POST.get('cancel', None):
mastodon.status_delete(id)
return redirect(home)
else:
return render(request, 'main/delete.html',
{"toot": toot, 'confirm_page': True,
"fullbrutalism": fullbrutalism_p(request)})