diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-07-24 04:30:51 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-07-24 04:30:51 -0700 |
commit | 74c96470722b67cdc240da8e3e75f93139afc741 (patch) | |
tree | 7c45eb27604448a52a25fc98f2f2fb7b0b6b88c8 | |
parent | 6e6a38cd734684590e9d588d04367c9fb2b75b41 (diff) | |
download | yt-local-74c96470722b67cdc240da8e3e75f93139afc741.tar.lz yt-local-74c96470722b67cdc240da8e3e75f93139afc741.tar.xz yt-local-74c96470722b67cdc240da8e3e75f93139afc741.zip |
POST on same page when removing from playlist, so url doesn't change
-rw-r--r-- | youtube/youtube.py | 18 | ||||
-rw-r--r-- | yt_local_playlist_template.html | 2 |
2 files changed, 11 insertions, 9 deletions
diff --git a/youtube/youtube.py b/youtube/youtube.py index a9bd3c4..93b947f 100644 --- a/youtube/youtube.py +++ b/youtube/youtube.py @@ -53,24 +53,26 @@ def youtube(env, start_response): return b'404 Not Found' elif method == "POST": + fields = urllib.parse.parse_qs(env['wsgi.input'].read().decode()) if path == "/edit_playlist": - fields = urllib.parse.parse_qs(env['wsgi.input'].read().decode()) if fields['action'][0] == 'add': local_playlist.add_to_playlist(fields['playlist_name'][0], fields['video_info_list']) start_response('204 No Content', ()) - elif fields['action'][0] == 'remove': - try: - playlist_name = fields['playlist_page'][0] - except KeyError: - playlist_name = fields['playlist_name'][0] + else: + start_response('400 Bad Request', ()) + return b'400 Bad Request' + + elif path.startswith("/playlists"): + if fields['action'][0] == 'remove': + playlist_name = path[11:] local_playlist.remove_from_playlist(playlist_name, fields['video_info_list']) start_response('200 OK', ()) return local_playlist.get_playlist_page(playlist_name).encode() + start_response('200 OK', (('Content-type','text/html'),) ) + return local_playlist.get_playlist_page(path[10:], query_string=query_string).encode() else: start_response('400 Bad Request', ()) return b'400 Bad Request' - - else: start_response('404 Not Found', ()) return b'404 Not Found' diff --git a/yt_local_playlist_template.html b/yt_local_playlist_template.html index 52836a6..d69fa48 100644 --- a/yt_local_playlist_template.html +++ b/yt_local_playlist_template.html @@ -63,7 +63,7 @@ $header <div id="left"> <h2 class="playlist-title">$title</h2> <input type="hidden" name="playlist_page" value="$title" form="playlist-edit"> - <button type="submit" id="playlist-remove-button" name="action" value="remove" form="playlist-edit">Remove from playlist</button> + <button type="submit" id="playlist-remove-button" name="action" value="remove" form="playlist-edit" formaction="">Remove from playlist</button> <div id="results"> $videos </div> |