aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-07-21 17:50:34 +0200
committerCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-07-21 17:50:34 +0200
commitd5200b2c9879938fe8e66c0016023d62a9b4f291 (patch)
treebd474e414f10c01c3779ee27a4dd3bc5f81e59be /pyaggr3g470r/views
parentUpdated translations. (diff)
parentimproving article listing : default icon and title for article link (diff)
downloadnewspipe-d5200b2c9879938fe8e66c0016023d62a9b4f291.tar.gz
newspipe-d5200b2c9879938fe8e66c0016023d62a9b4f291.tar.bz2
newspipe-d5200b2c9879938fe8e66c0016023d62a9b4f291.zip
Merged in jaesivsm/pyaggr3g470r (pull request #19)
small post vacations fix
Diffstat (limited to 'pyaggr3g470r/views')
-rw-r--r--pyaggr3g470r/views/feed.py17
-rw-r--r--pyaggr3g470r/views/views.py54
2 files changed, 48 insertions, 23 deletions
diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py
index 11f549e6..1a3ad938 100644
--- a/pyaggr3g470r/views/feed.py
+++ b/pyaggr3g470r/views/feed.py
@@ -105,13 +105,15 @@ def bookmarklet():
try:
feed = construct_feed_from(url)
- except requests.exceptions.ConnectionError as e:
- flash(gettext("Impossible to connect to the address: {}.".format(url)), "danger")
+ except requests.exceptions.ConnectionError:
+ flash(gettext("Impossible to connect to the address: {}.".format(url)),
+ "danger")
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"
- " RSS link manually and reactivate this feed"), 'warning')
+ " RSS link manually and reactivate this feed"),
+ 'warning')
feed = feed_contr.create(**feed)
flash(gettext('Feed was successfully created.'), 'success')
if feed.enabled and conf.CRAWLING_METHOD == "classic":
@@ -202,7 +204,12 @@ def icon(feed_id):
icon = FeedController(None if g.user.is_admin() else g.user.id)\
.get(id=feed_id).icon
etag = md5(icon.encode('utf8')).hexdigest()
- headers = {'Cache-Control': 'max-age=86400', 'ETag': etag}
+ headers = {'Cache-Control': 'max-age=86400', 'etag': etag}
if request.headers.get('if-none-match') == etag:
return Response(status=304, headers=headers)
- return Response(base64.b64decode(icon), mimetype='image', headers=headers)
+ if '\n' in icon:
+ content_type, icon = icon.split()
+ headers['content-type'] = content_type
+ else:
+ headers['content-type'] = 'application/image'
+ return Response(base64.b64decode(icon), headers=headers)
diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py
index 189fd53f..0071f887 100644
--- a/pyaggr3g470r/views/views.py
+++ b/pyaggr3g470r/views/views.py
@@ -30,11 +30,13 @@ import os
import string
import random
import hashlib
+import logging
import datetime
-from collections import namedtuple
+from collections import OrderedDict
+
from bootstrap import application as app, db
from flask import render_template, request, flash, session, \
- url_for, redirect, g, current_app, make_response
+ url_for, redirect, g, current_app, make_response, Response
from flask.ext.login import LoginManager, login_user, logout_user, \
login_required, current_user, AnonymousUserMixin
from flask.ext.principal import Principal, Identity, AnonymousIdentity, \
@@ -46,12 +48,13 @@ from sqlalchemy.exc import IntegrityError
from werkzeug import generate_password_hash
import conf
+from pyaggr3g470r.lib.utils import to_hash
from pyaggr3g470r import utils, notifications, export
from pyaggr3g470r.models import User, Feed, Article, Role
from pyaggr3g470r.decorators import feed_access_required
-from pyaggr3g470r.forms import SignupForm, SigninForm, \
- ProfileForm, UserForm, RecoverPasswordForm, \
- AddFeedForm, InformationMessageForm
+from pyaggr3g470r.forms import SignupForm, SigninForm, InformationMessageForm,\
+ ProfileForm, UserForm, RecoverPasswordForm \
+
from pyaggr3g470r.controllers import UserController, FeedController, \
ArticleController
@@ -62,6 +65,7 @@ admin_permission = Permission(RoleNeed('admin'))
login_manager = LoginManager()
login_manager.init_app(app)
+logger = logging.getLogger(__name__)
#
# Management of the user's session.
@@ -235,7 +239,6 @@ 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.count_by_feed(readed=False)
in_error = {feed.id: feed.error_count for feed in
feed_contr.read(error_count__gt=2)}
@@ -267,26 +270,41 @@ def render_home(filters=None, head_titles=None,
def gen_url(filter_=filter_, sort_=sort_, limit=limit, feed_id=feed_id,
**kwargs):
+ o_kwargs = OrderedDict()
+ for key in sorted(kwargs):
+ o_kwargs[key] = kwargs[key]
if page_to_render == 'search':
- kwargs['query'] = request.args.get('query', '')
- kwargs['search_title'] = request.args.get('search_title', 'off')
- kwargs['search_content'] = request.args.get(
+ o_kwargs['query'] = request.args.get('query', '')
+ o_kwargs['search_title'] = request.args.get('search_title', 'off')
+ o_kwargs['search_content'] = request.args.get(
'search_content', 'off')
- if kwargs['search_title'] == kwargs['search_content'] == 'off':
- kwargs['search_title'] = 'on'
- return url_for(page_to_render, filter_=filter_, sort_=sort_,
- limit=limit, feed_id=feed_id, **kwargs)
+ # if nor title and content are selected, selecting title
+ if o_kwargs['search_title'] == o_kwargs['search_content'] == 'off':
+ o_kwargs['search_title'] = 'on'
+ o_kwargs['filter_'] = filter_
+ o_kwargs['sort_'] = sort_
+ o_kwargs['limit'] = limit
+ o_kwargs['feed_id'] = feed_id
+ return url_for(page_to_render, **o_kwargs)
articles = list(articles)
if (page_to_render == 'home' and feed_id or page_to_render == 'search') \
and filter_ != 'all' and not articles:
return redirect(gen_url(filter_='all'))
- return render_template('home.html', page_to_render=page_to_render,
- gen_url=gen_url, feed_id=feed_id,
- filter_=filter_, limit=limit, feeds=feeds,
- unread=unread, articles=articles, in_error=in_error,
- head_titles=head_titles, sort_=sort_, **kwargs)
+ etag = to_hash("".join([str(filters[key]) for key in sorted(filters)])
+ + "".join([str(art.id) for art in articles]))
+ if request.headers.get('if-none-match') == etag:
+ return Response(status=304, headers={'etag': etag,
+ 'Cache-Control': 'pragma: no-cache'})
+ response = make_response(render_template('home.html', gen_url=gen_url,
+ feed_id=feed_id, page_to_render=page_to_render,
+ filter_=filter_, limit=limit, feeds=feeds,
+ unread=arti_contr.count_by_feed(readed=False),
+ articles=articles, in_error=in_error,
+ head_titles=head_titles, sort_=sort_, **kwargs))
+ response.headers['etag'] = etag
+ return response
@app.route('/')
bgstack15