From ed57d6090faf521a05a51786325fdd69cd794bf4 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sat, 29 Dec 2012 15:30:05 +0100 Subject: Template for the /history page. --- source/pyAggr3g470r.py | 87 ++----------------------------------------- source/templates/history.html | 80 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 84 deletions(-) create mode 100644 source/templates/history.html diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py index a2cb29da..73fc26a3 100755 --- a/source/pyAggr3g470r.py +++ b/source/pyAggr3g470r.py @@ -42,16 +42,12 @@ __license__ = "GPLv3" import os import re -import calendar - +import datetime import cherrypy from mako.template import Template from mako.lookup import TemplateLookup lookup = TemplateLookup(directories=['templates']) -from collections import Counter -import datetime - import conf import utils import export @@ -413,85 +409,8 @@ class pyAggr3g470r(object): This page enables to browse articles chronologically. """ feeds = self.mongo.get_all_feeds() - html = htmlheader() - html += htmlnav - html += """
\n""" - - # Get the date from the tag cloud - # Format: /history/?query=year:2011-month:06 to get the - # list of articles of June, 2011. - if m != "": - query = """year:%s-month:%s""" % tuple(m.split('-')) - - if query == "all": - html += "

Search with tags cloud

\n" - html += "

Choose a year

\n" - if "year" in query: - the_year = query.split('-')[0].split(':')[1] - if "month" not in query: - html += "

Choose a month for " + the_year + "

\n" - if "month" in query: - the_month = query.split('-')[1].split(':')[1] - html += "

Articles of "+ calendar.month_name[int(the_month)] + \ - ", "+ the_year +".

\n" - - timeline = Counter() - for feed in feeds: - new_feed_section = True - for article in self.mongo.get_articles(feed["feed_id"]): - - if query == "all": - timeline[article["article_date"].strftime('%Y')] += 1 - - elif query[:4] == "year": - - if article["article_date"].strftime('%Y') == the_year: - timeline[article["article_date"].strftime('%m')] += 1 - - if "month" in query: - if article["article_date"].strftime('%m') == the_month: - if article["article_readed"] == False: - # not readed articles are in bold - not_read_begin, not_read_end = "", "" - else: - not_read_begin, not_read_end = "", "" - - if article["article_like"] == True: - like = """ """ - else: - like = "" - # Descrition for the CSS ToolTips - article_content = utils.clear_string(article["article_content"]) - if article_content: - description = " ".join(article_content[:500].split(' ')[:-1]) - else: - description = "No description." - # Title of the article - article_title = article["article_title"] - if len(article_title) >= 80: - article_title = article_title[:80] + " ..." - - if new_feed_section is True: - new_feed_section = False - html += """

%s

\n""" % \ - (feed["feed_id"], feed["site_link"], feed["feed_title"], feed["feed_link"], feed["feed_image"]) - - html += article["article_date"].strftime("%a %d (%H:%M:%S) ") + " - " + \ - """%s%s%s%s""" % \ - (feed["feed_id"], article["article_id"], not_read_begin, \ - article_title, not_read_end, description) + like + "
\n" - if query == "all": - query_string = "year" - elif "year" in query: - query_string = "year:" + the_year + "-month" - if "month" not in query: - html += '
' + \ - utils.tag_cloud([(elem, timeline[elem]) for elem in timeline.keys()], query_string) + '
' - html += '
' - html += htmlfooter - return html + tmpl = lookup.get_template("history.html") + return tmpl.render(feeds=feeds, mongo=self.mongo, query=query, m=m) history.exposed = True diff --git a/source/templates/history.html b/source/templates/history.html new file mode 100644 index 00000000..e6826032 --- /dev/null +++ b/source/templates/history.html @@ -0,0 +1,80 @@ +## history.html +<%inherit file="base.html"/> +<% +import utils +import calendar +from collections import Counter +%> +
+ <% + html = "" + # Get the date from the tag cloud + # Format: /history/?query=year:2011-month:06 to get the + # list of articles of June, 2011. + if query == "all": + html += "

Search with tags cloud

\n" + html += "

Choose a year

\n" + if "year" in query: + the_year = query.split('-')[0].split(':')[1] + if "month" not in query: + html += "

Choose a month for " + the_year + "

\n" + if "month" in query: + the_month = query.split('-')[1].split(':')[1] + html += "

Articles of "+ calendar.month_name[int(the_month)] + ", "+ the_year +".

\n" + + timeline = Counter() + for feed in feeds: + new_feed_section = True + for article in mongo.get_articles(feed["feed_id"]): + + if query == "all": + timeline[article["article_date"].strftime('%Y')] += 1 + + elif query[:4] == "year": + + if article["article_date"].strftime('%Y') == the_year: + timeline[article["article_date"].strftime('%m')] += 1 + + if "month" in query: + if article["article_date"].strftime('%m') == the_month: + if article["article_readed"] == False: + # not readed articles are in bold + not_read_begin, not_read_end = "", "" + else: + not_read_begin, not_read_end = "", "" + + if article["article_like"] == True: + like = """ """ + else: + like = "" + # Descrition for the CSS ToolTips + article_content = utils.clear_string(article["article_content"]) + if article_content: + description = " ".join(article_content[:500].split(' ')[:-1]) + else: + description = "No description." + # Title of the article + article_title = article["article_title"] + if len(article_title) >= 80: + article_title = article_title[:80] + " ..." + + if new_feed_section is True: + new_feed_section = False + html += """

%s

\n""" % \ + (feed["feed_id"], feed["site_link"], feed["feed_title"], feed["feed_link"], feed["feed_image"]) + + html += article["article_date"].strftime("%a %d (%H:%M:%S) ") + " - " + \ + """%s%s%s%s""" % \ + (feed["feed_id"], article["article_id"], not_read_begin, \ + article_title, not_read_end, description) + like + "
\n" + if query == "all": + query_string = "year" + elif "year" in query: + query_string = "year:" + the_year + "-month" + if "month" not in query: + html += '
' + \ + utils.tag_cloud([(elem, timeline[elem]) for elem in timeline.keys()], query_string) + '
' + %> + ${html} \ No newline at end of file -- cgit