From cf7f17b93e67e25748a08cc6fd1686fce22c72df Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Tue, 27 Nov 2012 23:57:33 +0100 Subject: Template for the /index page. --- source/pyAggr3g470r.py | 114 ++------------------------------------------ source/templates/index.html | 103 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 110 deletions(-) create mode 100644 source/templates/index.html diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py index f7e3c21c..f967fced 100755 --- a/source/pyAggr3g470r.py +++ b/source/pyAggr3g470r.py @@ -147,120 +147,14 @@ class pyAggr3g470r(object): html = htmlheader((nb_unread_articles and \ ['(' + str(nb_unread_articles) +')'] or \ [""])[0]) - html += htmlnav - html += self.create_right_menu() - html += """
\n""" - - if feeds: - html += '\n' - html += '\n' - html += '      \n' - - html += """\n""" % \ - (nb_favorites,) - - html += """\n""" % \ - (nb_mail_notifications,) - - html += '      ' - if nb_unread_articles != 0: - html += '\n' - html += """\n""" % \ - (nb_unread_articles,) - html += '\n' - - - # The main page display all the feeds. - for feed in feeds: - html += """

%s -

\n""" % \ - (feed["feed_id"], feed["site_link"], feed["feed_title"], \ - feed["feed_link"], feed["feed_image"]) - - # The main page display only 10 articles by feeds. - for article in self.mongo.get_articles_from_collection(feed["feed_id"], limit=10): - if article["article_readed"] == False: - # not readed articles are in bold - not_read_begin, not_read_end = "", "" - else: - not_read_begin, not_read_end = "", "" - # display a heart for faved articles - 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.split(' ')[:55]) - else: - description = "No description." - # Title of the article - article_title = article["article_title"] - if len(article_title) >= 80: - article_title = article_title[:80] + " ..." - - # 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%s%s""" % \ - (feed["feed_id"], article["article_id"], not_read_begin, \ - article_title, not_read_end, description) + like + "
\n" - html += "
\n" - - # some options for the current feed - html += """All articles   """ % (feed["feed_id"],) - html += """Feed summary   """ % (feed["feed_id"],) - if self.mongo.nb_unread_articles(feed["feed_id"]) != 0: - html += """  Mark all as read""" % (feed["feed_id"],) - html += """     Unread article(s) (%s)""" % (feed["feed_id"], self.mongo.nb_unread_articles(feed["feed_id"])) - if feed["mail"] == "0": - html += """
\nStay tuned""" % (feed["feed_id"],) - else: - html += """
\nStop staying tuned""" % (feed["feed_id"],) - html += """

Top

""" - html += "
\n" - html += htmlfooter - return html + tmpl = lookup.get_template("index.html") + return tmpl.render(feeds=feeds, mongo=self.mongo, nb_favorites=nb_favorites, \ + nb_unread_articles=nb_unread_articles, \ + nb_mail_notifications=nb_mail_notifications) index.exposed = True - @require() - def create_right_menu(self): - """ - Create the right menu. - """ - html = """
\n""" - html += """
\n""" - html += "
\n" - # insert the list of feeds in the menu - html += self.create_list_of_feeds() - html += "
\n" - - return html - - @require() - def create_list_of_feeds(self): - """ - Create the list of feeds. - """ - feeds = self.mongo.get_all_feeds() - html = """" - @require() def management(self): """ diff --git a/source/templates/index.html b/source/templates/index.html new file mode 100644 index 00000000..17f05b57 --- /dev/null +++ b/source/templates/index.html @@ -0,0 +1,103 @@ +## articles.html +<%inherit file="base.html"/> +<% +import utils +%> +
+
+ +
+
+ +
+ +
+ %if feeds: + + +        + + +        + %if nb_unread_articles != 0: + + + %endif + %endif + + <% + html = "" + %> + <% + for feed in feeds: + html += """

%s +

\n""" % \ + (feed["feed_id"], feed["site_link"], feed["feed_title"], \ + feed["feed_link"], feed["feed_image"]) + + # The main page display only 10 articles by feeds. + for article in mongo.get_articles_from_collection(feed["feed_id"], limit=10): + if article["article_readed"] == False: + # not readed articles are in bold + not_read_begin, not_read_end = "", "" + else: + not_read_begin, not_read_end = "", "" + + # display a heart for faved articles + 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.split(' ')[:55]) + else: + description = "No description." + # Title of the article + article_title = article["article_title"] + if len(article_title) >= 80: + article_title = article_title[:80] + " ..." + + # 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%s%s""" % \ + (feed["feed_id"], article["article_id"], not_read_begin, \ + article_title, not_read_end, description) + like + "
\n" + html += "
\n" + + # some options for the current feed + html += """All articles   """ % (feed["feed_id"],) + html += """Feed summary   """ % (feed["feed_id"],) + if mongo.nb_unread_articles(feed["feed_id"]) != 0: + html += """  Mark all as read""" % (feed["feed_id"],) + html += """     Unread article(s) (%s)""" % (feed["feed_id"], mongo.nb_unread_articles(feed["feed_id"])) + if feed["mail"] == "0": + html += """
\nStay tuned""" % (feed["feed_id"],) + else: + html += """
\nStop staying tuned""" % (feed["feed_id"],) + html += """

Top

""" + html += "
\n" + %> + ${html} -- cgit