diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-05-24 22:26:47 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-05-24 22:26:47 +0200 |
commit | 05f30c772b71fd30115ec012a3371f4478b74192 (patch) | |
tree | 78582f430ec00fbbfc59fe5164eecf04b702e007 /src/web | |
parent | A bookmarklet for bookmarks has been added. (diff) | |
download | newspipe-05f30c772b71fd30115ec012a3371f4478b74192.tar.gz newspipe-05f30c772b71fd30115ec012a3371f4478b74192.tar.bz2 newspipe-05f30c772b71fd30115ec012a3371f4478b74192.zip |
Import bookmarks from pinboard.in
Diffstat (limited to 'src/web')
-rw-r--r-- | src/web/templates/edit_bookmark.html | 14 | ||||
-rw-r--r-- | src/web/views/bookmark.py | 15 |
2 files changed, 26 insertions, 3 deletions
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 @@ </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 class="row"> + <div class="col-md-6 pull-right"> + <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> + <div class="col-md-6"> + <form action="{{ url_for('bookmark.import_pinboard') }}" method="post" id="formImportPinboard" enctype="multipart/form-data"> + <span class="btn btn-default btn-file">{{ _('Import bookmarks from pinboard.in') }} (<span class="text-info">*.json</span>)<input type="file" name="jsonfile" /></span> + <button class="btn btn-default" type="submit">OK</button> + </form> + </div> </div> {% endif %} </div><!-- /.container --> 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()) |