From 66fa65dfca37c3fa1a86af8b9e265b82f181e2fd Mon Sep 17 00:00:00 2001 From: pluja Date: Sun, 23 Aug 2020 17:36:00 +0200 Subject: [PATCH] Follow/Unfollow from channel page --- app/routes.py | 12 +++++++----- app/templates/channel.html | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/routes.py b/app/routes.py index 1386405..ffe05d2 100644 --- a/app/routes.py +++ b/app/routes.py @@ -264,13 +264,13 @@ def ytfollow(channelId): db.session.commit() except: flash("Something went wrong. Try again!") - return redirect(url_for('invidious')) + return redirect(request.referrer) flash('You are following {}!'.format(channelId)) else: flash("Something went wrong... try again") - return redirect(url_for('ytsearch')) + return redirect(request.referrer) else: - return redirect(url_for('ytsearch')) + return redirect(request.referrer) @app.route('/ytunfollow/', methods=['POST']) @login_required @@ -283,17 +283,19 @@ def ytunfollow(channelId): flash("User unfollowed!") except: flash("There was an error unfollowing the user. Try again.") - return redirect(url_for('ytsearch')) + return redirect(request.referrer) @app.route('/channel/', methods=['GET']) @login_required def channel(id): + form = ChannelForm() + button_form = EmptyForm() data = requests.get('https://www.youtube.com/feeds/videos.xml?channel_id={id}'.format(id=id)) data = feedparser.parse(data.content) channelData = YoutubeSearch.channelInfo(id) - return render_template('channel.html', channel=channelData[0], videos=channelData[1]) + return render_template('channel.html', form=form, btform=button_form, channel=channelData[0], videos=channelData[1]) @app.route('/watch', methods=['GET']) @login_required diff --git a/app/templates/channel.html b/app/templates/channel.html index dc5b119..1eb41e3 100644 --- a/app/templates/channel.html +++ b/app/templates/channel.html @@ -14,7 +14,22 @@ -
+
+ {% if not current_user.is_following_yt(channel.id) %} +

+

+ {{ btform.hidden_tag() }} + {{ btform.submit(value='Follow') }} +
+

+ {% else %} +

+

+ {{ btform.hidden_tag() }} + {{ btform.submit(value='Unfollow') }} +
+

+ {% endif %}