From abb2117238514a965c8a756885970e652fc493a8 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Tue, 29 Jan 2013 22:40:51 +0100 Subject: Added /languages page which displays articles sorted by language. --- source/pyAggr3g470r.py | 25 +++++++++++++++++++++++++ source/templates/languages.html | 15 +++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 source/templates/languages.html diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py index cecb73ff..5e979dac 100755 --- a/source/pyAggr3g470r.py +++ b/source/pyAggr3g470r.py @@ -451,6 +451,31 @@ class pyAggr3g470r(object): inactives.exposed = True + @auth.require() + def languages(self): + """ + Filter by languages. + """ + try: + from guess_language import guess_language + except: + tmpl = lookup.get_template("error.html") + return tmpl.render(message="

Module guess_language not installed.

") + result = {} + feeds = self.mongo.get_all_feeds() + for feed in feeds: + for article in self.mongo.get_articles(feed["feed_id"]): + language = guess_language(utils.clear_string(article["article_content"])) + if language not in result.keys(): + result[language] = {} + if feed["feed_title"] not in result[language].keys(): + result[language][feed["feed_title"]] = [] + result[language][feed["feed_title"]].append(article) + tmpl = lookup.get_template("languages.html") + return tmpl.render(articles_sorted_by_languages=result) + + languages.exposed = True + @auth.require() def add_feed(self, url): """ diff --git a/source/templates/languages.html b/source/templates/languages.html new file mode 100644 index 00000000..202f02c8 --- /dev/null +++ b/source/templates/languages.html @@ -0,0 +1,15 @@ +## languages.html +<%inherit file="base.html"/> +
+ %for language in articles_sorted_by_languages.keys(): +

${language}

+ %for feed in articles_sorted_by_languages[language]: +

${feed}

+ %for article in articles_sorted_by_languages[language][feed]: + ${article["article_title"]} +
+ %endfor +
+ %endfor +
+ %endfor \ No newline at end of file -- cgit