diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-02-12 16:41:09 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-02-12 16:41:09 +0100 |
commit | 8bd82176356540b88eece24b96d7eb6a2260d718 (patch) | |
tree | 619caf62c174d09448e3da9c873b2df0d26dd5c2 /src/web/views | |
parent | New https certificate (diff) | |
download | newspipe-8bd82176356540b88eece24b96d7eb6a2260d718.tar.gz newspipe-8bd82176356540b88eece24b96d7eb6a2260d718.tar.bz2 newspipe-8bd82176356540b88eece24b96d7eb6a2260d718.zip |
prototypefor bookmarks
Diffstat (limited to 'src/web/views')
-rw-r--r-- | src/web/views/__init__.py | 3 | ||||
-rw-r--r-- | src/web/views/bookmark.py | 80 | ||||
-rw-r--r-- | src/web/views/category.py | 2 |
3 files changed, 83 insertions, 2 deletions
diff --git a/src/web/views/__init__.py b/src/web/views/__init__.py index e0e49927..41bb52f3 100644 --- a/src/web/views/__init__.py +++ b/src/web/views/__init__.py @@ -6,11 +6,12 @@ from web.views.category import category_bp, categories_bp from web.views.icon import icon_bp from web.views.admin import admin_bp from web.views.user import user_bp, users_bp +from web.views.bookmark import bookmark_bp, bookmarks_bp __all__ = ['views', 'home', 'session_mgmt', 'v2', 'v3', 'article_bp', 'articles_bp', 'feed_bp', 'feeds_bp', 'category_bp', 'categories_bp', 'icon_bp', - 'admin_bp', 'user_bp', 'users_bp'] + 'admin_bp', 'user_bp', 'users_bp', 'bookmark_bp', 'bookmarks_bp'] import conf from flask import request diff --git a/src/web/views/bookmark.py b/src/web/views/bookmark.py new file mode 100644 index 00000000..d780a3ae --- /dev/null +++ b/src/web/views/bookmark.py @@ -0,0 +1,80 @@ +import logging +from werkzeug.exceptions import BadRequest + +from flask import Blueprint, render_template, flash, \ + redirect, request, url_for +from flask_babel import gettext +from flask_login import login_required, current_user + +import conf +from bootstrap import db +from web.forms import BookmarkForm +from web.controllers import BookmarkController + +logger = logging.getLogger(__name__) +bookmarks_bp = Blueprint('bookmarks', __name__, url_prefix='/bookmarks') +bookmark_bp = Blueprint('bookmark', __name__, url_prefix='/bookmark') + + +@bookmarks_bp.route('/', methods=['GET']) +@login_required +def list(): + "Lists the bookmarks." + bookmark_contr = BookmarkController(current_user.id) + return render_template('bookmarks.html', + bookmarks=BookmarkController(current_user.id).read().order_by('time')) + + +@bookmark_bp.route('/create', methods=['GET']) +@bookmark_bp.route('/edit/<int:bookmark_id>', methods=['GET']) +@login_required +def form(bookmark_id=None): + action = gettext("Add a bookmark") + head_titles = [action] + if bookmark_id is None: + return render_template('edit_bookmark.html', action=action, + head_titles=head_titles, form=BookmarkForm()) + bookmark = BookmarkController(current_user.id).get(id=bookmark_id) + action = gettext('Edit bookmark') + head_titles = [action] + form = BookmarkForm(obj=bookmark) + form.tags.data = ", ".join(bookmark.tags) + return render_template('edit_bookmark.html', action=action, + head_titles=head_titles, bookmark=bookmark, + form=form) + + +@bookmark_bp.route('/create', methods=['POST']) +@bookmark_bp.route('/edit/<int:bookmark_id>', methods=['POST']) +@login_required +def process_form(bookmark_id=None): + form = BookmarkForm() + bookmark_contr = BookmarkController(current_user.id) + + if not form.validate(): + return render_template('edit_bookmark.html', form=form) + + # Edit an existing bookmark + bookmark_attr = {'href': form.href.data, + 'description': form.description.data, + 'extended': form.extended.data, + 'tags': [tag.strip() for tag in form.tags.data.split(',')], + 'shared': form.shared.data, + 'to_read': form.to_read.data} + + if bookmark_id is not None: + bookmark = BookmarkController(current_user.id).get(id=bookmark_id) + form.populate_obj(bookmark) + bookmark.tags = [tag.strip() for tag in form.tags.data.split(',')] + db.session.commit() + + #bookmark_contr.update({'id': bookmark_id}, bookmark_attr) + flash(gettext('Bookmark successfully updated.'), 'success') + return redirect(url_for('bookmark.form', bookmark_id=bookmark_id)) + + # Create a new bookmark + new_bookmark = bookmark_contr.create(**bookmark_attr) + + flash(gettext('Bookmark successfully created.'), 'success') + + return redirect(url_for('bookmark.form', bookmark_id=new_bookmark.id)) diff --git a/src/web/views/category.py b/src/web/views/category.py index 2bdcf9cc..138561dd 100644 --- a/src/web/views/category.py +++ b/src/web/views/category.py @@ -16,7 +16,7 @@ category_bp = Blueprint('category', __name__, url_prefix='/category') @login_required @etag_match def list_(): - "Lists the subscribed feeds in a table." + "Lists the subscribed feeds in a table." art_contr = ArticleController(current_user.id) return render_template('categories.html', categories=list(CategoryController(current_user.id).read().order_by('name')), |