From 1b561fa90e955512fce0079d762937051a71c9af Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Mon, 30 Apr 2018 18:40:41 -0400 Subject: [PATCH] Enable favoriting toots. The user flow for this is kind of crap right now; it will get better once some intercooler is applied on top, but will stay the same in lynx and FULLBRUTALISM --- brutaldon/templates/main/fav.html | 31 ++++++++++++++++++++++ brutaldon/templates/main/toot_partial.html | 14 +++++++--- brutaldon/urls.py | 1 + brutaldon/views.py | 12 +++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 brutaldon/templates/main/fav.html diff --git a/brutaldon/templates/main/fav.html b/brutaldon/templates/main/fav.html new file mode 100644 index 0000000..d60792b --- /dev/null +++ b/brutaldon/templates/main/fav.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} + +{% block title %} Brutaldon - confirm favorite {% endblock %} + +{% block content %} + {% if toot.favourited %} +

Unfav that toot?

+ {% else %} +

Fav that toot?

+ {% endif %} + +
+ {% include "main/toot_partial.html" with toot=toot %} +
+
+ {% csrf_token %} +
+
+
+ +
+
+
+
+ +
+
+
+
+{% endblock %} diff --git a/brutaldon/templates/main/toot_partial.html b/brutaldon/templates/main/toot_partial.html index 214a27e..0e5ac09 100644 --- a/brutaldon/templates/main/toot_partial.html +++ b/brutaldon/templates/main/toot_partial.html @@ -73,10 +73,16 @@ - - - - + + + {% if toot.favourited %} + + {% else %} + + {% endif %} + + +
diff --git a/brutaldon/urls.py b/brutaldon/urls.py index 5dfad68..c3277c7 100644 --- a/brutaldon/urls.py +++ b/brutaldon/urls.py @@ -30,5 +30,6 @@ urlpatterns = [ path('thread/', views.thread, name='thread'), path('toot', views.toot, name="toot"), path('reply/', views.reply, name='reply'), + path('fav/', views.fav, name='fav'), path('', views.home), ] diff --git a/brutaldon/views.py b/brutaldon/views.py index b916d9c..1da6cac 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -194,3 +194,15 @@ def reply(request, id): 'fullbrutalism': fullbrutalism_p(request)}) else: return redirect(reply, id) + +def fav(request, id): + mastodon = get_mastodon(request) + toot = mastodon.status(id) + if request.method == 'POST': + if toot.favourited: + mastodon.status_unfavourite(id) + else: + mastodon.status_favourite(id) + return redirect(thread, id) + else: + return render(request, 'main/fav.html', {"toot": toot})