From 4f03d7b324360f718780fcbdfc359f60896fead4 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Sun, 24 May 2015 19:09:35 +0200 Subject: accelerating the feeds page --- pyaggr3g470r/views/feed.py | 3 ++- pyaggr3g470r/views/views.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 51832ea5..f940e22d 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -24,7 +24,8 @@ feed_bp = Blueprint('feed', __name__, url_prefix='/feed') def feeds(): "Lists the subscribed feeds in a table." return render_template('feeds.html', - feeds=FeedController(g.user.id).read()) + feeds=FeedController(g.user.id).read(), + article_count=ArticleController(g.user.id).count_by_feed()) @feed_bp.route('/', methods=['GET']) diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 77f3b147..e0bd1dcb 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -246,7 +246,7 @@ def render_home(filters=None, head_titles=None, arti_contr = ArticleController(g.user.id) feeds = {feed.id: feed.title for feed in feed_contr.read()} - unread = arti_contr.get_unread() + unread = arti_contr.count_by_feed(readed=False) in_error = {feed.id: feed.error_count for feed in feed_contr.read(error_count__gt=2)} -- cgit From be33517445c787be0da5577da048d4b2d91452d4 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Thu, 28 May 2015 15:27:21 +0200 Subject: adding unread count when listing feeds, using count_by_feed for user management --- pyaggr3g470r/views/feed.py | 5 ++++- pyaggr3g470r/views/views.py | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index f940e22d..d50d0883 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -23,9 +23,12 @@ feed_bp = Blueprint('feed', __name__, url_prefix='/feed') @login_required def feeds(): "Lists the subscribed feeds in a table." + art_contr = ArticleController(g.user.id) return render_template('feeds.html', feeds=FeedController(g.user.id).read(), - article_count=ArticleController(g.user.id).count_by_feed()) + unread_article_count=art_contr.count_by_feed(readed=False), + article_count=art_contr.count_by_feed(), + ) @feed_bp.route('/', methods=['GET']) diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index e0bd1dcb..a4e799cc 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -736,9 +736,14 @@ def user(user_id=None): """ See information about a user (stations, etc.). """ - user = User.query.filter(User.id == user_id).first() + user = UserController().get(id=user_id) if user is not None: - return render_template('/admin/user.html', user=user) + article_contr = ArticleController(user_id) + return render_template('/admin/user.html', user=user, + article_count=article_contr.count_by_feed(), + unread_article_count=article_contr.count_by_feed(readed=False), + ) + else: flash(gettext('This user does not exist.'), 'danger') return redirect(redirect_url()) -- cgit From c9b8d7ce0eba10fa3e0f0f0b87ad9f9479589062 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Tue, 9 Jun 2015 12:06:53 +0200 Subject: a more bootstrap edit feed page & removing unused code --- pyaggr3g470r/views/article.py | 1 - pyaggr3g470r/views/feed.py | 12 +----------- 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/article.py b/pyaggr3g470r/views/article.py index 5843551e..6de07ad3 100644 --- a/pyaggr3g470r/views/article.py +++ b/pyaggr3g470r/views/article.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 - from flask import Blueprint, g, render_template, redirect -from sqlalchemy import desc from pyaggr3g470r import controllers, utils from pyaggr3g470r.decorators import pyagg_default_decorator diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index d50d0883..022980f4 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -27,8 +27,7 @@ def feeds(): return render_template('feeds.html', feeds=FeedController(g.user.id).read(), unread_article_count=art_contr.count_by_feed(readed=False), - article_count=art_contr.count_by_feed(), - ) + article_count=art_contr.count_by_feed()) @feed_bp.route('/', methods=['GET']) @@ -110,15 +109,6 @@ def bookmarklet(): return redirect(url_for('feed.form', feed_id=feed.id)) -@feed_bp.route('/read/', methods=['GET', 'POST']) -@login_required -def read(feed_id): - FeedController(g.user.id).update(readed=True) - flash(gettext('Feed successfully updated.', - feed_title=feed.title), 'success') - return redirect(request.referrer or url_for('home')) - - @feed_bp.route('/update//', methods=['GET', 'POST']) @feeds_bp.route('/update/', methods=['GET', 'POST']) @login_required -- cgit From ffe491466a3c9b7096e32d263fd5b35bf3415559 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Thu, 2 Jul 2015 14:16:14 +0200 Subject: basic UI to maniuplate filters --- pyaggr3g470r/views/feed.py | 103 ++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 49 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 022980f4..8bd2f8e9 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -122,59 +122,64 @@ def update(action, feed_id=None): return redirect(request.referrer or url_for('home')) -@feed_bp.route('/create', methods=['GET', 'POST', 'PUT']) -@feed_bp.route('/edit/', methods=['GET', 'POST']) +@feed_bp.route('/create', methods=['GET']) +@feed_bp.route('/edit/', methods=['GET']) @login_required def form(feed_id=None): + action = gettext("Add a feed") + head_titles = [action] + if feed_id is None: + return render_template('edit_feed.html', action=action, + head_titles=head_titles, form=AddFeedForm()) + feed = FeedController(g.user.id).get(id=feed_id) + action = gettext('Edit feed') + head_titles = [action] + if feed.title: + head_titles.append(feed.title) + return render_template('edit_feed.html', action=action, + head_titles=head_titles, + form=AddFeedForm(obj=feed), feed=feed) + + +@feed_bp.route('/create', methods=['POST']) +@feed_bp.route('/edit/', methods=['POST']) +@login_required +def process_form(feed_id=None): form = AddFeedForm() feed_contr = FeedController(g.user.id) - if request.method == 'POST': - if not form.validate(): - return render_template('edit_feed.html', form=form) - existing_feeds = list(feed_contr.read(link=form.link.data)) - if existing_feeds and feed_id is None: - flash(gettext("Couldn't add feed: feed already exists."), - "warning") - return redirect(url_for('feed.form', - feed_id=existing_feeds[0].id)) - # Edit an existing feed - if feed_id is not None: - feed_contr.update({'id': feed_id}, - {'title': form.title.data, - 'link': form.link.data, - 'enabled': form.enabled.data, - 'site_link': form.site_link.data}) - flash(gettext('Feed %(feed_title)r successfully updated.', - feed_title=form.title.data), 'success') - return redirect(url_for('feed.form', feed_id=feed_id)) - - # Create a new feed - new_feed = FeedController(g.user.id).create( - title=form.title.data, - description="", - link=form.link.data, - site_link=form.site_link.data, - enabled=form.enabled.data) - - flash(gettext('Feed %(feed_title)r successfully created.', - feed_title=new_feed.title), 'success') - - if conf.CRAWLING_METHOD == "classic": - utils.fetch(g.user.id, new_feed.id) - flash(gettext("Downloading articles for the new feed..."), 'info') - - return redirect(url_for('feed.form', - feed_id=new_feed.id)) + if not form.validate(): + return render_template('edit_feed.html', form=form) + existing_feeds = list(feed_contr.read(link=form.link.data)) + if existing_feeds and feed_id is None: + flash(gettext("Couldn't add feed: feed already exists."), "warning") + return redirect(url_for('feed.form', feed_id=existing_feeds[0].id)) + # Edit an existing feed + feed_attr = {'title': form.title.data, 'enabled': form.enabled.data, + 'link': form.link.data, 'site_link': form.site_link.data, + 'filters': []} + + for filter_attr in ('type', 'pattern', 'action on', 'action'): + for i, value in enumerate( + request.form.getlist(filter_attr.replace(' ', '_'))): + if i >= len(feed_attr['filters']): + feed_attr['filters'].append({}) + feed_attr['filters'][i][filter_attr] = value - # Getting the form for an existing feed if feed_id is not None: - feed = FeedController(g.user.id).get(id=feed_id) - form = AddFeedForm(obj=feed) - return render_template('edit_feed.html', - action=gettext("Edit the feed"), - form=form, feed=feed) - - # Return an empty form in order to create a new feed - return render_template('edit_feed.html', action=gettext("Add a feed"), - form=form) + feed_contr.update({'id': feed_id}, feed_attr) + flash(gettext('Feed %(feed_title)r successfully updated.', + feed_title=feed_attr['title']), 'success') + return redirect(url_for('feed.form', feed_id=feed_id)) + + # Create a new feed + new_feed = FeedController(g.user.id).create(**feed_attr) + + flash(gettext('Feed %(feed_title)r successfully created.', + feed_title=new_feed.title), 'success') + + if conf.CRAWLING_METHOD == "classic": + utils.fetch(g.user.id, new_feed.id) + flash(gettext("Downloading articles for the new feed..."), 'info') + + return redirect(url_for('feed.form', feed_id=new_feed.id)) -- cgit