aboutsummaryrefslogtreecommitdiff
path: root/src/web/views/bookmark.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2017-05-24 08:37:33 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2017-05-24 08:37:33 +0200
commit6a757e240e74b46d8c9d100882e50b5c7bc2d823 (patch)
tree5e9a1bdb6cdcfec9ea860ada844c27b19cd1a080 /src/web/views/bookmark.py
parentUpdated README. (diff)
downloadnewspipe-6a757e240e74b46d8c9d100882e50b5c7bc2d823.tar.gz
newspipe-6a757e240e74b46d8c9d100882e50b5c7bc2d823.tar.bz2
newspipe-6a757e240e74b46d8c9d100882e50b5c7bc2d823.zip
A bookmarklet for bookmarks has been added.
Diffstat (limited to 'src/web/views/bookmark.py')
-rw-r--r--src/web/views/bookmark.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/web/views/bookmark.py b/src/web/views/bookmark.py
index 70d9bf9a..546f4996 100644
--- a/src/web/views/bookmark.py
+++ b/src/web/views/bookmark.py
@@ -96,3 +96,31 @@ def delete(bookmark_id=None):
flash(gettext("Bookmark %(bookmark_name)s successfully deleted.",
bookmark_name=bookmark.title), 'success')
return redirect(redirect_url())
+
+
+@bookmark_bp.route('/bookmarklet', methods=['GET', 'POST'])
+@login_required
+def bookmarklet():
+ bookmark_contr = BookmarkController(current_user.id)
+ href = (request.args if request.method == 'GET' else request.form)\
+ .get('href', None)
+ if not href:
+ flash(gettext("Couldn't add bookmark: url missing."), "error")
+ raise BadRequest("url is missing")
+
+ bookmark_exists = bookmark_contr.read(**{'href': href}).all()
+ if bookmark_exists:
+ flash(gettext("Couldn't add bookmark: bookmark already exists."),
+ "warning")
+ return redirect(url_for('bookmark.form',
+ bookmark_id=bookmark_exists[0].id))
+
+ bookmark_attr = {'href': href,
+ 'description': '',
+ 'title': href,
+ 'shared': False,
+ 'to_read': True}
+
+ new_bookmark = bookmark_contr.create(**bookmark_attr)
+ flash(gettext('Bookmark successfully created.'), 'success')
+ return redirect(url_for('bookmark.form', bookmark_id=new_bookmark.id))
bgstack15