From cb946f37fce86ac8a2d4d44b876cbbf0404cb351 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sat, 29 Dec 2012 15:57:25 +0100 Subject: Template for the /unread page. --- source/pyAggr3g470r.py | 74 ++----------------------------------------- source/templates/unread.html | 75 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 72 deletions(-) create mode 100644 source/templates/unread.html (limited to 'source') diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py index 6d8d801a..bd389a0f 100755 --- a/source/pyAggr3g470r.py +++ b/source/pyAggr3g470r.py @@ -323,78 +323,8 @@ class pyAggr3g470r(object): This page displays all unread articles of a feed. """ feeds = self.mongo.get_all_feeds() - html = htmlheader() - html += htmlnav - html += """
""" - if self.mongo.nb_unread_articles() != 0: - - # List unread articles of all the database - if feed_id == "": - html += "

Unread article(s)

" - html += """\n
\nMark articles as read\n
\n""" - for feed in feeds: - new_feed_section = True - nb_unread = 0 - - # For all unread article of the current feed. - for article in self.mongo.get_articles(feed["feed_id"], condition=("article_readed", False)): - nb_unread += 1 - 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"]) - - # 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." - - # a description line per article (date, title of the article and - # CSS description tooltips on mouse over) - html += article["article_date"].strftime('%Y-%m-%d %H:%M') + " - " + \ - """%s%s
\n""" % \ - (feed["feed_id"], article["article_id"], article["article_title"][:150], description) - - if nb_unread == self.mongo.nb_unread_articles(feed["feed_id"]): - html += """
\nMark all articles from this feed as read\n""" % \ - (feed["feed_id"],) - html += """
\nMark articles as read\n""" - - # List unread articles of a feed - else: - try: - feed = self.mongo.get_feed(feed_id) - except: - self.error("This feed do not exists.") - html += """

Unread article(s) of the feed %s

-
""" % (feed_id, feed["feed_title"]) - - # For all unread article of the feed. - for article in self.mongo.get_articles(feed_id, condition=("article_readed", False)): - # 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." - - # a description line per article (date, title of the article and - # CSS description tooltips on mouse over) - html += article["article_date"].strftime('%Y-%m-%d %H:%M') + " - " + \ - """%s%s
\n""" % \ - (feed_id, article["article_id"], article["article_title"][:150], description) - - html += """
\nMark all as read""" % (feed_id,) - # No unread article - else: - html += '

No unread article(s)

\n
\nWhy not check for news?' - html += """\n

All feeds

""" - html += "
\n" - html += htmlfooter - return html - + tmpl = lookup.get_template("unread.html") + return tmpl.render(feeds=feeds, feed_id=feed_id, mongo=self.mongo) unread.exposed = True @require() diff --git a/source/templates/unread.html b/source/templates/unread.html new file mode 100644 index 00000000..32201531 --- /dev/null +++ b/source/templates/unread.html @@ -0,0 +1,75 @@ +## unread.html +<%inherit file="base.html"/> +<% +import utils +%> +
+ <% + html = "" + if mongo.nb_unread_articles() != 0: + + # List unread articles of all the database + if feed_id == "": + html += "

Unread article(s)

" + html += """\n
\nMark articles as read\n
\n""" + for feed in feeds: + new_feed_section = True + nb_unread = 0 + + # For all unread article of the current feed. + for article in mongo.get_articles(feed["feed_id"], condition=("article_readed", False)): + nb_unread += 1 + 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"]) + + # 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." + + # a description line per article (date, title of the article and + # CSS description tooltips on mouse over) + html += article["article_date"].strftime('%Y-%m-%d %H:%M') + " - " + \ + """%s%s
\n""" % \ + (feed["feed_id"], article["article_id"], article["article_title"][:150], description) + + if nb_unread == mongo.nb_unread_articles(feed["feed_id"]): + html += """
\nMark all articles from this feed as read\n""" % \ + (feed["feed_id"],) + html += """
\nMark articles as read\n""" + + # List unread articles of a feed + else: + try: + feed = mongo.get_feed(feed_id) + except: + error("This feed do not exists.") + html += """

Unread article(s) of the feed %s

+
""" % (feed_id, feed["feed_title"]) + + # For all unread article of the feed. + for article in mongo.get_articles(feed_id, condition=("article_readed", False)): + # 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." + + # a description line per article (date, title of the article and + # CSS description tooltips on mouse over) + html += article["article_date"].strftime('%Y-%m-%d %H:%M') + " - " + \ + """%s%s
\n""" % \ + (feed_id, article["article_id"], article["article_title"][:150], description) + + html += """
\nMark all as read""" % (feed_id,) + # No unread article + else: + html += '

No unread article(s)

\n
\nWhy not check for news?' + html += """\n

All feeds

""" + %> + ${html} \ No newline at end of file -- cgit