diff options
author | Cédric Bonhomme <kimble.mandel+bitbucket@gmail.com> | 2015-07-02 18:56:27 +0200 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel+bitbucket@gmail.com> | 2015-07-02 18:56:27 +0200 |
commit | b43010d2da88d91e8934ba7214a823453cbf6031 (patch) | |
tree | 6e8e1fd8d45832a59f8ec37e2009cc68069f2375 /pyaggr3g470r/views | |
parent | Display a picto when a feed is disabled due to errors when retrieving. (diff) | |
parent | using conf.DEFAULT_MAX_ERROR in feed template (diff) | |
download | newspipe-b43010d2da88d91e8934ba7214a823453cbf6031.tar.gz newspipe-b43010d2da88d91e8934ba7214a823453cbf6031.tar.bz2 newspipe-b43010d2da88d91e8934ba7214a823453cbf6031.zip |
Merged in jaesivsm/pyaggr3g470r (pull request #14)
Master
Diffstat (limited to 'pyaggr3g470r/views')
-rw-r--r-- | pyaggr3g470r/views/article.py | 1 | ||||
-rw-r--r-- | pyaggr3g470r/views/feed.py | 117 | ||||
-rw-r--r-- | pyaggr3g470r/views/views.py | 11 |
3 files changed, 66 insertions, 63 deletions
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 51832ea5..8bd2f8e9 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -23,8 +23,11 @@ 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()) + feeds=FeedController(g.user.id).read(), + unread_article_count=art_contr.count_by_feed(readed=False), + article_count=art_contr.count_by_feed()) @feed_bp.route('/<int:feed_id>', methods=['GET']) @@ -106,15 +109,6 @@ def bookmarklet(): return redirect(url_for('feed.form', feed_id=feed.id)) -@feed_bp.route('/read/<int:feed_id>', 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/<action>/<int:feed_id>', methods=['GET', 'POST']) @feeds_bp.route('/update/<action>', methods=['GET', 'POST']) @login_required @@ -128,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/<int:feed_id>', methods=['GET', 'POST']) +@feed_bp.route('/create', methods=['GET']) +@feed_bp.route('/edit/<int:feed_id>', 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/<int:feed_id>', 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') + 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 - return redirect(url_for('feed.form', - feed_id=new_feed.id)) - - # 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)) diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 77f3b147..a4e799cc 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)} @@ -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()) |