aboutsummaryrefslogtreecommitdiff
path: root/src/web/views/feed.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-02-03 07:11:37 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-02-03 07:11:37 +0100
commitda929a367c3f1fe5f3546be82e47111c2fa84ad3 (patch)
tree89380f41b802256d8fdbf724e7d9e63b48209b4a /src/web/views/feed.py
parentMerge pull request #30 from jaesivsm/master (diff)
parentwriting a bit of doc, moving crawler together (diff)
downloadnewspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.tar.gz
newspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.tar.bz2
newspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.zip
Merge pull request #31 from jaesivsm/master
redoing UI
Diffstat (limited to 'src/web/views/feed.py')
-rw-r--r--src/web/views/feed.py68
1 files changed, 55 insertions, 13 deletions
diff --git a/src/web/views/feed.py b/src/web/views/feed.py
index 2a9b2da8..959179f9 100644
--- a/src/web/views/feed.py
+++ b/src/web/views/feed.py
@@ -1,14 +1,13 @@
#! /usr/bin/env python
# -*- coding: utf-8 -
-import base64
+import logging
import requests.exceptions
-from hashlib import md5
from datetime import datetime, timedelta
from sqlalchemy import desc
from werkzeug.exceptions import BadRequest
from flask import Blueprint, g, render_template, flash, \
- redirect, request, url_for, Response
+ redirect, request, url_for
from flask.ext.babel import gettext
from flask.ext.login import login_required
@@ -17,8 +16,10 @@ from web import utils
from web.lib.view_utils import etag_match
from web.lib.feed_utils import construct_feed_from
from web.forms import AddFeedForm
-from web.controllers import FeedController, ArticleController
+from web.controllers import (CategoryController, FeedController,
+ ArticleController)
+logger = logging.getLogger(__name__)
feeds_bp = Blueprint('feeds', __name__, url_prefix='/feeds')
feed_bp = Blueprint('feed', __name__, url_prefix='/feed')
@@ -42,9 +43,12 @@ def feed(feed_id=None):
"Presents detailed information about a feed."
feed = FeedController(g.user.id).get(id=feed_id)
word_size = 6
+ category = None
+ if feed.category_id:
+ category = CategoryController(g.user.id).get(id=feed.category_id)
articles = ArticleController(g.user.id) \
.read(feed_id=feed_id) \
- .order_by(desc("Article.date")).all()
+ .order_by(desc("date")).all()
top_words = utils.top_words(articles, n=50, size=int(word_size))
tag_cloud = utils.tag_cloud(top_words)
@@ -65,7 +69,7 @@ def feed(feed_id=None):
head_titles=[utils.clear_string(feed.title)],
feed=feed, tag_cloud=tag_cloud,
first_post_date=first_article,
- end_post_date=last_article,
+ end_post_date=last_article, category=category,
average=average, delta=delta, elapsed=elapsed)
@@ -91,11 +95,12 @@ def reset_errors(feed_id):
return redirect(request.referrer or url_for('home'))
-@feed_bp.route('/bookmarklet', methods=['GET'])
+@feed_bp.route('/bookmarklet', methods=['GET', 'POST'])
@login_required
def bookmarklet():
feed_contr = FeedController(g.user.id)
- url = request.args.get('url', None)
+ url = (request.args if request.method == 'GET' else request.form)\
+ .get('url', None)
if not url:
flash(gettext("Couldn't add feed: url missing."), "error")
raise BadRequest("url is missing")
@@ -112,6 +117,9 @@ def bookmarklet():
flash(gettext("Impossible to connect to the address: {}.".format(url)),
"danger")
return redirect(url_for('home'))
+ except Exception:
+ logger.exception('something bad happened when fetching %r', url)
+ return redirect(url_for('home'))
if not feed.get('link'):
feed['enabled'] = False
flash(gettext("Couldn't find a feed url, you'll need to find a Atom or"
@@ -149,18 +157,23 @@ def update(action, feed_id=None):
@etag_match
def form(feed_id=None):
action = gettext("Add a feed")
+ categories = CategoryController(g.user.id).read()
head_titles = [action]
if feed_id is None:
+ form = AddFeedForm()
+ form.set_category_choices(categories)
return render_template('edit_feed.html', action=action,
- head_titles=head_titles, form=AddFeedForm())
+ head_titles=head_titles, form=form)
feed = FeedController(g.user.id).get(id=feed_id)
+ form = AddFeedForm(obj=feed)
+ form.set_category_choices(categories)
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)
+ head_titles=head_titles, categories=categories,
+ form=form, feed=feed)
@feed_bp.route('/create', methods=['POST'])
@@ -169,6 +182,7 @@ def form(feed_id=None):
def process_form(feed_id=None):
form = AddFeedForm()
feed_contr = FeedController(g.user.id)
+ form.set_category_choices(CategoryController(g.user.id).read())
if not form.validate():
return render_template('edit_feed.html', form=form)
@@ -179,7 +193,9 @@ def process_form(feed_id=None):
# 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': []}
+ 'filters': [], 'category_id': form.category_id.data}
+ if not feed_attr['category_id']:
+ del feed_attr['category_id']
for filter_attr in ('type', 'pattern', 'action on', 'action'):
for i, value in enumerate(
@@ -195,7 +211,7 @@ def process_form(feed_id=None):
return redirect(url_for('feed.form', feed_id=feed_id))
# Create a new feed
- new_feed = FeedController(g.user.id).create(**feed_attr)
+ new_feed = feed_contr.create(**feed_attr)
flash(gettext('Feed %(feed_title)r successfully created.',
feed_title=new_feed.title), 'success')
@@ -205,3 +221,29 @@ def process_form(feed_id=None):
flash(gettext("Downloading articles for the new feed..."), 'info')
return redirect(url_for('feed.form', feed_id=new_feed.id))
+
+
+@feeds_bp.route('/inactives', methods=['GET'])
+@login_required
+def inactives():
+ """
+ List of inactive feeds.
+ """
+ nb_days = int(request.args.get('nb_days', 365))
+ inactives = FeedController(g.user.id).get_inactives(nb_days)
+ return render_template('inactives.html',
+ inactives=inactives, nb_days=nb_days)
+
+
+@feed_bp.route('/duplicates/<int:feed_id>', methods=['GET'])
+@login_required
+def duplicates(feed_id):
+ """
+ Return duplicates article for a feed.
+ """
+ feed, duplicates = FeedController(g.user.id).get_duplicates(feed_id)
+ if len(duplicates) == 0:
+ flash(gettext('No duplicates in the feed "{}".').format(feed.title),
+ 'info')
+ return redirect('home')
+ return render_template('duplicates.html', duplicates=duplicates, feed=feed)
bgstack15