aboutsummaryrefslogtreecommitdiff
path: root/src/web
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
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')
-rw-r--r--src/web/templates/edit_bookmark.html6
-rw-r--r--src/web/views/bookmark.py28
2 files changed, 34 insertions, 0 deletions
diff --git a/src/web/templates/edit_bookmark.html b/src/web/templates/edit_bookmark.html
index 384e641c..573e3d7a 100644
--- a/src/web/templates/edit_bookmark.html
+++ b/src/web/templates/edit_bookmark.html
@@ -62,5 +62,11 @@
</div>
</form>
</div>
+ {% if action == "Add a bookmark" %}
+ <div>
+ <p>{{ _('You can add a bookmark with a bookmarklet. Drag the following button to your browser bookmarks.') }}</p>
+ {{ _('<a class="btn btn-default" href="%(bookmarklet)s" rel="bookmark">Manage your bookmarks using Newspipe</a>', bookmarklet='javascript:window.location="%s?href="+encodeURIComponent(document.location)' % url_for('bookmark.bookmarklet', _external=True)) }}
+ </div>
+ {% endif %}
</div><!-- /.container -->
{% endblock %}
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