From 665878be6d433296c1386beace0fced0b77bfe7b Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 13 Dec 2012 22:42:36 +0100 Subject: Template for the /feed page. --- source/pyAggr3g470r.py | 115 ++++-------------------------------------- source/templates/feed.html | 122 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 105 deletions(-) create mode 100644 source/templates/feed.html (limited to 'source') diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py index 9bc53b3e..22649ec9 100755 --- a/source/pyAggr3g470r.py +++ b/source/pyAggr3g470r.py @@ -292,120 +292,25 @@ class pyAggr3g470r(object): nb_unread_articles_feed = self.mongo.nb_unread_articles(feed_id) except KeyError: return self.error("This feed do not exists.") - html = htmlheader() - html += htmlnav - html += """
""" - html += "

The feed " + feed["feed_title"] + " contains " + str(nb_articles_feed) + " articles. " - html += "Representing " + str((round(float(nb_articles_feed) / nb_articles_total, 4)) * 100) + " percent of the total " - html += "(" + str(nb_articles_total) + ").

" - if articles != []: - html += "

" + (nb_unread_articles_feed == 0 and ["All articles are read"] or [str(nb_unread_articles_feed) + \ - " unread article" + (nb_unread_articles_feed == 1 and [""] or ["s"])[0]])[0] + ".

" - if feed["mail"] == True: - html += """

You are receiving articles from this feed to the address: %s. """ % \ - (conf.mail_to, conf.mail_to) - html += """Stop receiving articles from this feed.

""" % \ - (feed_id, ) if articles != []: last_article = utils.string_to_datetime(str(articles[0]["article_date"])) first_article = utils.string_to_datetime(str(articles[self.mongo.nb_articles(feed_id)-2]["article_date"])) delta = last_article - first_article delta_today = datetime.datetime.fromordinal(datetime.date.today().toordinal()) - last_article - html += "

The last article was posted " + str(abs(delta_today.days)) + " day(s) ago.

" - if delta.days > 0: - html += """

Daily average: %s,""" % (str(round(float(nb_articles_feed) / abs(delta.days), 2)),) - html += """ between the %s and the %s.

\n""" % \ - (str(articles[nb_articles_feed-2]["article_date"])[:10], str(articles[0]["article_date"])[:10]) - - html += "

Recent articles

" - for article in articles: - 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[: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] + " ..." - - # 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 += """All articles   \n""" % (feed["feed_id"],) - html += "
\n" - - - if self.mongo.nb_favorites(feed_id) != 0: - html += "

Your favorites articles for this feed

" - for article in self.mongo.get_favorites(feed_id): - #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) - - - # This section enables the user to edit informations about - # the current feed: - # - feed logo; - # - feed name; - # - URL of the feed (not the site); - html += "
\n

Edit this feed

\n" - html += '\n\n
' + \ - '' + \ - """
\n""" % \ - (feed["feed_id"],) - html += '\n\n
' + \ - '' + \ - """
\n""" % \ - (feed["feed_id"], feed["feed_link"]) - html += '\n\n
' + \ - '' + \ - """
\n""" % \ - (feed["feed_id"],) + average = round(float(nb_articles_feed) / abs(delta.days), 2) + favorites = self.mongo.get_favorites(feed_id) dic = {} top_words = utils.top_words(articles = self.mongo.get_articles(feed_id), n=50, size=int(word_size)) - html += "
\n

Tag cloud

\n" - # Tags cloud - html += """
\n""" % (feed["feed_id"],) - html += "Minimum size of a word:\n" - html += """
\n""" % (word_size,) - html += '
' + \ - utils.tag_cloud(top_words) + '
' - - html += "
" - html += "
" - html += htmlfooter - return html + tag_cloud = utils.tag_cloud(top_words) + + tmpl = lookup.get_template("feed.html") + return tmpl.render(feed=feed, articles=articles, favorites=favorites, \ + nb_articles_feed=nb_articles_feed, nb_articles_total=nb_articles_total, nb_unread_articles_feed=nb_unread_articles_feed, \ + first_post_date=first_article, end_post_date=last_article, \ + average=average, delta=delta, delta_today=delta_today, \ + tag_cloud=tag_cloud, word_size=word_size, mail_to=conf.mail_to) feed.exposed = True diff --git a/source/templates/feed.html b/source/templates/feed.html new file mode 100644 index 00000000..5fc5d170 --- /dev/null +++ b/source/templates/feed.html @@ -0,0 +1,122 @@ +## feed.html +<%inherit file="base.html"/> +<% +import utils +%> +
+

The feed ${feed['feed_title']} contains ${nb_articles_feed} articles. +Representing ${(round(float(nb_articles_feed) / nb_articles_total, 4)) * 100} percent of the total (${nb_articles_total}).

+ +%if articles: +

${(nb_unread_articles_feed == 0 and ["All articles are read"] or [str(nb_unread_articles_feed) + " unread article" + (nb_unread_articles_feed == 1 and [""] or ["s"])[0]])[0]}.

+%endif + +%if feed["mail"] == True: +

You are receiving articles from this feed to the address: ${mail_to}. + Stop receiving articles from this feed.

+%endif + +%if articles != []: +

The last article was posted ${delta_today.days} day(s) ago.

+ %if delta_today.days > 0: +

Daily average: ${average}, between the ${first_post_date} and the ${end_post_date}.

+ %endif + + +
+

Recent articles

+ <% + html = "" + %> + %for article in articles: + <% + 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[: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] + " ..." + + # 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" + %> + %endfor + ${html} + + All articles    +
+ + %if nb_favorites != 0: +

+

Your favorites articles for this feed

+ <% + html = "" + %> + %for article in favorites: + <% + #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) + %> + %endfor + ${html} + %endif +%endif + + + +
+

Edit this feed

+
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+

Tag cloud

+
+ Minimum size of a word: + +
+
${tag_cloud}
\ No newline at end of file -- cgit