aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2015-03-16 07:22:52 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2015-03-16 07:22:52 +0100
commit8d0fea82761f2fdc1ea93687429990eefa851fc8 (patch)
treef93d515b5694efbb7b94ee02e361473731c8d4dc /pyaggr3g470r
parentforgot login required decorator (diff)
downloadnewspipe-8d0fea82761f2fdc1ea93687429990eefa851fc8.tar.gz
newspipe-8d0fea82761f2fdc1ea93687429990eefa851fc8.tar.bz2
newspipe-8d0fea82761f2fdc1ea93687429990eefa851fc8.zip
Improvements and fixes for the history() function.
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/templates/history.html2
-rwxr-xr-xpyaggr3g470r/utils.py24
-rw-r--r--pyaggr3g470r/views/views.py9
3 files changed, 15 insertions, 20 deletions
diff --git a/pyaggr3g470r/templates/history.html b/pyaggr3g470r/templates/history.html
index 6216f616..2d64da98 100644
--- a/pyaggr3g470r/templates/history.html
+++ b/pyaggr3g470r/templates/history.html
@@ -10,7 +10,7 @@
<li class="list-group-item"><a href="/history/{{ year }}/{{ article }}">{{ article }}</a> : {{ articles_counter[article] }} articles</li>
{% else %}
{% for article in articles %}
- <li class="list-group-item"><a href="/article/{{ article.id }}">{{ article.title | safe }}</a></li>
+ <li class="list-group-item">{{ article.date }} - <a href="/article/{{ article.id }}">{{ article.title | safe }}</a></li>
{% endfor %}
{% endif %}
{% endfor %}
diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py
index ae140327..1ad2896a 100755
--- a/pyaggr3g470r/utils.py
+++ b/pyaggr3g470r/utils.py
@@ -43,6 +43,7 @@ import operator
import urllib
import itertools
import subprocess
+import sqlalchemy
try:
from urlparse import urlparse, parse_qs, urlunparse
except:
@@ -85,25 +86,18 @@ def fetch(id, feed_id=None):
cmd = [conf.PYTHON, conf.basedir+'/manager.py', 'fetch_asyncio', str(id), str(feed_id)]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
-def history(year=None, month=None):
+def history(user_id, year=None, month=None):
"""
"""
- import datetime, time, sqlalchemy
articles_counter = Counter()
- if None != month and None != year:
- articles = controllers.ArticleController(1).read(). \
- filter(sqlalchemy.extract('year', Article.date) == year). \
- filter(sqlalchemy.extract('month', Article.date) == month)
- elif None != year:
- articles = controllers.ArticleController(1).read(). \
- filter(sqlalchemy.extract('year', Article.date) == year)
- else:
- articles = controllers.ArticleController(1).read()
-
- for article in articles:
+ articles = controllers.ArticleController(user_id).read()
+ if None != year:
+ articles = articles.filter(sqlalchemy.extract('year', Article.date) == year)
if None != month:
- articles_counter[article.date.day] += 1
- elif None != year:
+ articles = articles.filter(sqlalchemy.extract('month', Article.date) == month)
+ print(articles.count())
+ for article in articles.all():
+ if None != year:
articles_counter[article.date.month] += 1
else:
articles_counter[article.date.year] += 1
diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py
index c6f0d3d0..9aefd6b1 100644
--- a/pyaggr3g470r/views/views.py
+++ b/pyaggr3g470r/views/views.py
@@ -543,10 +543,11 @@ def management():
@app.route('/history/<int:year>/<int:month>', methods=['GET'])
@login_required
def history(year=None, month=None):
- articles_counter, articles = utils.history(year, month)
- return render_template('history.html', articles_counter=articles_counter,
- articles=articles,
- year=year, month=month)
+ articles_counter, articles = utils.history(g.user.id, year, month)
+ return render_template('history.html',
+ articles_counter=articles_counter,
+ articles=articles,
+ year=year, month=month)
@app.route('/bookmarklet', methods=['GET'])
@app.route('/create_feed', methods=['GET', 'POST'])
bgstack15