aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-12 16:01:13 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-12 16:01:13 +0200
commit2bd9ab12c2f3551e6ad2ffa05282d87711adbf6b (patch)
tree25467b4d7e3a68d913fc0079bc21ecc80a01147b
parentRemoved install.sh file. (diff)
downloadnewspipe-2bd9ab12c2f3551e6ad2ffa05282d87711adbf6b.tar.gz
newspipe-2bd9ab12c2f3551e6ad2ffa05282d87711adbf6b.tar.bz2
newspipe-2bd9ab12c2f3551e6ad2ffa05282d87711adbf6b.zip
The /home page is now loading faster.
-rw-r--r--pyaggr3g470r/templates/home.html10
-rw-r--r--pyaggr3g470r/views.py14
2 files changed, 17 insertions, 7 deletions
diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html
index 6363ee06..6448fc15 100644
--- a/pyaggr3g470r/templates/home.html
+++ b/pyaggr3g470r/templates/home.html
@@ -1,10 +1,10 @@
{% extends "layout.html" %}
{% block content %}
<div class="container">
- {% if user.feeds.all()|count == 0 %}
+ {% if result|count == 0 %}
<h1>You are not subscribed to any feed. <a href="/create_feed/">Fix this</a>.</h1>
{% else %}
- {% for feed in user.feeds|sort(attribute="title") %}
+ {% for feed in result|sort(attribute="title") %}
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>{{ feed.title|safe }}</h1>
@@ -17,7 +17,7 @@
<a href="/mark_as_read/{{ feed.id }}"><i class="glyphicon glyphicon-check" title="Mark all as read"></i></a>
</div>
</div>
- {% for number in range(0, feed.articles[0:9]|count-(feed.articles[0:9]|count % 3), 3) %}
+ {% for number in range(0, feed.articles.all()|count-(feed.articles.all()|count % 3), 3) %}
<div class="row">
{% for n in range(number, number+3) %}
<div class="col-xs-6 col-sm-4 col-md-4">
@@ -29,9 +29,9 @@
{% endfor %}
</div>
{% endfor %}
- {% if feed.articles[0:9]|count % 3 != 0 %}
+ {% if feed.articles.all()|count % 3 != 0 %}
<div class="row">
- {% for n in range(feed.articles[0:9]|count-(feed.articles[0:9]|count % 3), feed.articles[0:9]|count) %}
+ {% for n in range(feed.articles.all()|count-(feed.articles.all()|count % 3), feed.articles.all()|count) %}
<div class="col-xs-6 col-sm-4 col-md-4">
{% if feed.articles[n].readed %}<h3>{% else %}<h1>{% endif %}
<a href="/article/{{ feed.articles[n].id }}">{{ feed.articles[n].title|safe }}</a>
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index c1eeec42..0e419dba 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -31,6 +31,7 @@ import datetime
from flask import render_template, jsonify, request, flash, session, url_for, redirect, g, current_app, make_response
from flask.ext.login import LoginManager, login_user, logout_user, login_required, current_user, AnonymousUserMixin
from flask.ext.principal import Principal, Identity, AnonymousIdentity, identity_changed, identity_loaded, Permission, RoleNeed, UserNeed
+from sqlalchemy import desc
from werkzeug import generate_password_hash
import conf
@@ -167,8 +168,16 @@ def home():
The home page lists most recent articles of all feeds.
"""
user = User.query.filter(User.email == g.user.email).first()
+ result = []
+ for feed in user.feeds:
+ new_feed = Feed()
+ new_feed.id = feed.id
+ new_feed.title = feed.title
+ new_feed.enabled = feed.enabled
+ new_feed.articles = Article.query.filter(Article.user_id == g.user.id, Article.feed_id == feed.id).order_by(desc("Article.date")).limit(9)
+ result.append(new_feed)
unread_articles = len(Article.query.filter(Article.user_id == g.user.id, Article.readed == False).all())
- return render_template('home.html', user=user, head_title=unread_articles)
+ return render_template('home.html', result=result, head_title=unread_articles)
@app.route('/fetch/', methods=['GET'])
@app.route('/fetch/<feed_id>', methods=['GET'])
@@ -277,7 +286,7 @@ def like(article_id=None):
db.session.commit()
return redirect(redirect_url())
-@app.route('/delete/<int:article_id>', methods=['GET'])
+@app.route('/delete/<int:article_id>/', methods=['GET'])
@login_required
def delete(article_id=None):
"""
@@ -522,6 +531,7 @@ def delete_feed(feed_id=None):
db.session.delete(feed)
db.session.commit()
flash('Feed "' + feed.title + '" successfully deleted.', 'success')
+ return redirect(redirect_url())
@app.route('/profile/', methods=['GET', 'POST'])
@login_required
bgstack15