~cedric/newspipe

d15d428a59df925c9cb25ea869d7007132cb4416 — Cédric Bonhomme 4 years ago 05f30c7
Import from pinboard is now faster. Bookmarks are sorted by time.
M src/lib/data.py => src/lib/data.py +5 -2
@@ 37,6 37,7 @@ from flask import jsonify

from bootstrap import db
from web.models import User, Feed, Article
from web.models.tag import BookmarkTag
from web.controllers import BookmarkController, BookmarkTagController




@@ 171,10 172,10 @@ def import_pinboard_json(user, json_content):
    tag_contr = BookmarkTagController(user.id)
    bookmarks = json.loads(json_content.decode("utf-8"))
    nb_bookmarks = 0
    for bookmark in bookmarks[:20]:
    for bookmark in bookmarks:
        tags = []
        for tag in bookmark['tags'].split(' '):
            new_tag = tag_contr.create(text=tag.strip(), user_id=user.id)
            new_tag = BookmarkTag(text=tag.strip(), user_id=user.id)
            tags.append(new_tag)
        bookmark_attr = {
                    'href': bookmark['href'],


@@ 182,6 183,8 @@ def import_pinboard_json(user, json_content):
                    'title': bookmark['description'],
                    'shared': [bookmark['shared']=='yes' and True or False][0],
                    'to_read': [bookmark['toread']=='yes' and True or False][0],
                    'time': datetime.datetime.strptime(bookmark['time'],
                                                        '%Y-%m-%dT%H:%M:%SZ'),
                    'tags': tags
                    }
        new_bookmark = bookmark_contr.create(**bookmark_attr)

M src/web/models/article.py => src/web/models/article.py +1 -1
@@ 28,7 28,7 @@ __license__ = "GPLv3"

from bootstrap import db
from datetime import datetime
from sqlalchemy import asc, desc, Index
from sqlalchemy import Index
from sqlalchemy.ext.associationproxy import association_proxy

from web.models.right_mixin import RightMixin

M src/web/templates/bookmarks.html => src/web/templates/bookmarks.html +4 -4
@@ 1,7 1,6 @@
{% extends "layout.html" %}
{% block content %}
<div class="container">
    <h1>{{ _('Bookmarks') }}</h1>
    <ul class="list-group">
    {% for bookmark in bookmarks %}
        <li class="list-group-item">


@@ 11,9 10,10 @@
                </h4>
                <p class="list-group-item-text">
                    <div class="text-muted">{{ bookmark.description }}</div>
                    {{ " ".join(bookmark.tags_proxy) }}
                    <a href="{{ url_for('bookmark.form', bookmark_id=bookmark.id) }}">edit</a>
                    <a href="{{ url_for('bookmark.delete', bookmark_id=bookmark.id) }}">delete</a>
                    <div>{{ " ".join(bookmark.tags_proxy) }}</div>
                    {{ bookmark.time }}
                    <a class="text-muted" href="{{ url_for('bookmark.form', bookmark_id=bookmark.id) }}">edit</a>
                    <a class="text-muted" href="{{ url_for('bookmark.delete', bookmark_id=bookmark.id) }}">delete</a>
                </p>
            </a>
        </li>

M src/web/views/bookmark.py => src/web/views/bookmark.py +7 -3
@@ 5,6 5,7 @@ from flask import Blueprint, render_template, flash, \
                  redirect, request, url_for
from flask_babel import gettext
from flask_login import login_required, current_user
from sqlalchemy import desc

import conf
from lib.utils import redirect_url


@@ 22,9 23,12 @@ bookmark_bp = Blueprint('bookmark', __name__, url_prefix='/bookmark')
@login_required
def list():
    "Lists the bookmarks."
    head_titles = ["Bookmarks"]
    bookmark_contr = BookmarkController(current_user.id)
    return render_template('bookmarks.html',
        bookmarks=BookmarkController(current_user.id).read().order_by('time'))
        head_titles=head_titles,
        bookmarks=BookmarkController(current_user.id) \
                    .read().order_by(desc('time')))


@bookmark_bp.route('/create', methods=['GET'])


@@ 135,7 139,7 @@ def import_pinboard():
            nb_bookmarks = import_pinboard_json(current_user, bookmarks.read())
            flash(gettext("%(nb_bookmarks)s bookmarks successfully imported.",
                          nb_bookmarks=nb_bookmarks), 'success')
        except:
        except Exception as e:
            flash(gettext('Error when importing bookmarks.'), 'error')
    

    return redirect(redirect_url())