From fb5df6041fc7bf97429bfe689e26fdc08e7e307f Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 15 Mar 2015 23:59:14 +0100 Subject: A new test for the history page. --- pyaggr3g470r/templates/history.html | 89 +++++++------------------------------ pyaggr3g470r/utils.py | 26 +++++++++++ pyaggr3g470r/views/views.py | 11 +++-- 3 files changed, 50 insertions(+), 76 deletions(-) diff --git a/pyaggr3g470r/templates/history.html b/pyaggr3g470r/templates/history.html index 0194cb89..6216f616 100644 --- a/pyaggr3g470r/templates/history.html +++ b/pyaggr3g470r/templates/history.html @@ -1,74 +1,19 @@ - {% extends "layout.html" %} - {% block head %} -{{ super() }} - - -{% endblock %} - +{% extends "layout.html" %} {% block content %}
-

History

-
-
-
- - - - - -
-{% endblock %} \ No newline at end of file +

{{ _('History') }}

+ +
+{% endblock %} diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py index ba440c78..ae140327 100755 --- a/pyaggr3g470r/utils.py +++ b/pyaggr3g470r/utils.py @@ -54,6 +54,7 @@ from contextlib import contextmanager import conf from flask import g +from pyaggr3g470r import controllers from pyaggr3g470r.models import User, Feed, Article @@ -84,6 +85,31 @@ 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): + """ + """ + 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: + if None != month: + articles_counter[article.date.day] += 1 + elif None != year: + articles_counter[article.date.month] += 1 + else: + articles_counter[article.date.year] += 1 + + return articles_counter, articles + def import_opml(email, opml_content): """ Import new feeds from an OPML file. diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index 88835068..b7ccf955 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -539,10 +539,13 @@ def management(): not_on_heroku = not conf.ON_HEROKU) @app.route('/history', methods=['GET']) -@login_required -def history(): - #user = User.query.filter(User.id == g.user.id).first() - return render_template('history.html') +@app.route('/history/', methods=['GET']) +@app.route('/history//', methods=['GET']) +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) @app.route('/bookmarklet', methods=['GET']) @app.route('/create_feed', methods=['GET', 'POST']) -- cgit