From 05f30c772b71fd30115ec012a3371f4478b74192 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 24 May 2017 22:26:47 +0200 Subject: Import bookmarks from pinboard.in --- src/web/templates/edit_bookmark.html | 14 +++++++++++--- src/web/views/bookmark.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src/web') diff --git a/src/web/templates/edit_bookmark.html b/src/web/templates/edit_bookmark.html index 573e3d7a..1c6f0c01 100644 --- a/src/web/templates/edit_bookmark.html +++ b/src/web/templates/edit_bookmark.html @@ -63,9 +63,17 @@ {% if action == "Add a bookmark" %} -
-

{{ _('You can add a bookmark with a bookmarklet. Drag the following button to your browser bookmarks.') }}

- {{ _('Manage your bookmarks using Newspipe', bookmarklet='javascript:window.location="%s?href="+encodeURIComponent(document.location)' % url_for('bookmark.bookmarklet', _external=True)) }} +
+
+

{{ _('You can add a bookmark with a bookmarklet. Drag the following button to your browser bookmarks.') }}

+ {{ _('Manage your bookmarks using Newspipe', bookmarklet='javascript:window.location="%s?href="+encodeURIComponent(document.location)' % url_for('bookmark.bookmarklet', _external=True)) }} +
+
+
+ {{ _('Import bookmarks from pinboard.in') }} (*.json) + +
+
{% endif %}
diff --git a/src/web/views/bookmark.py b/src/web/views/bookmark.py index 546f4996..87142024 100644 --- a/src/web/views/bookmark.py +++ b/src/web/views/bookmark.py @@ -8,6 +8,7 @@ from flask_login import login_required, current_user import conf from lib.utils import redirect_url +from lib.data import import_pinboard_json from bootstrap import db from web.forms import BookmarkForm from web.controllers import BookmarkController, BookmarkTagController @@ -124,3 +125,17 @@ def bookmarklet(): new_bookmark = bookmark_contr.create(**bookmark_attr) flash(gettext('Bookmark successfully created.'), 'success') return redirect(url_for('bookmark.form', bookmark_id=new_bookmark.id)) + +@bookmark_bp.route('/import_pinboard', methods=['POST']) +@login_required +def import_pinboard(): + bookmarks = request.files.get('jsonfile', None) + if bookmarks: + try: + nb_bookmarks = import_pinboard_json(current_user, bookmarks.read()) + flash(gettext("%(nb_bookmarks)s bookmarks successfully imported.", + nb_bookmarks=nb_bookmarks), 'success') + except: + flash(gettext('Error when importing bookmarks.'), 'error') + + return redirect(redirect_url()) -- cgit