## 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 += """
\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}