aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views/feed.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyaggr3g470r/views/feed.py')
-rw-r--r--pyaggr3g470r/views/feed.py117
1 files changed, 58 insertions, 59 deletions
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))
bgstack15