]> git.ipfire.org Git - people/shoehn/ipfire.org.git/commitdiff
RSS feed and minor improvements.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Jan 2011 16:05:30 +0000 (17:05 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Jan 2011 16:05:30 +0000 (17:05 +0100)
www/templates/admin-base.html
www/templates/base.html
www/templates/news-author.html
www/templates/news-item.html
www/templates/rss.xml
www/webapp/__init__.py
www/webapp/backend/news.py
www/webapp/handlers.py
www/webapp/handlers_base.py
www/webapp/handlers_news.py
www/webapp/ui_modules.py

index de3b12a347dfc85ab114cadc6c27bc157472c74c..c069b536f14daf01d343b9f5f0685fb0f772f3b1 100644 (file)
@@ -5,9 +5,9 @@
 {% block sidebar %}
        <h4>{{ _("Options") }}</h4>
 
-       <ul>
-               <li><a href="/accounts">{{ _("Accounts") }}</a></li>
-               <li><a href="/mirrors">{{ _("Mirrors") }}</a></li>
+       <ul class="list">
+               <!-- <li><a href="/accounts">{{ _("Accounts") }}</a></li> -->
+               <!-- <li><a href="/mirrors">{{ _("Mirrors") }}</a></li> -->
                <li><a href="/planet">{{ _("Planet") }}</a></li>
        </ul>
 {% end %}
index 06d0b634320b4409646799358c404882e353b129..73d269fafb5a4e87edc2cc1ba3b01cca4d65c9b1 100644 (file)
@@ -26,8 +26,9 @@
                        <script src="{{ static_url("js/correctpng.js") }}" type="text/javascript"></script>
                <![endif]-->
 
-               <!-- RSS -->
-               <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.ipfire.org/{{ lang }}/news.rss" />
+               {% if rss_url %}
+                       <link rel="alternate" type="application/rss+xml" title="RSS" href="{{ rss_url }}" />
+               {% end %}
        </head>
        <body>
                <div id="header">
index e8379c079e372a0ea16db20e2210e812f93043f3..5794f00199ddc707c1ac9674b817e4568762a0eb 100644 (file)
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base-2.html" %}
 
 {% block title %}{{ author.cn }}{% end block %}
 
@@ -9,7 +9,7 @@
        </p>
 
        <h3>{{ _("%s recently announced...") % author.cn }}</h3>
-       <ul class="news_author_latest_news">
+       <ul class="list news_author_latest_news">
        {% for news in latest_news %}
                <li>{{ modules.NewsLine(news) }}</li>
        {% end %}
index 6b54f976c6165a3c8c8f06e102309b0354ea15c4..d41ca09403a3f60ba3efdb9960a1a81d89733391 100644 (file)
@@ -16,7 +16,7 @@
 
 {% block sidebar %}
        <h4>other options</h4>
-       <ul>
+       <ul class="list">
                <li><a href="/news">{{ _("Show all news") }}</a></li>
        </ul>
 {% end block %}
index ebb0e3e4b3c8f4ec74e700dc1a94efcdd435e7df..f87c9ddff22953f1eed6cb62d6635c971cb0b2a7 100644 (file)
@@ -9,14 +9,14 @@
                <pubDate>Thu, 8 Nov 2007 00:00:00 +0200</pubDate>
                {% for item in items %}
                        <item>
-                               <title>{{ item.subject }}</title>
-                               <link>http://www.ipfire.org/{{ lang }}/news</link>
-                               <author>{{ item.mail }} ({{ item.author }})</author>
-                               <guid>http://www.ipfire.org/{{ lang }}/news#{{ item.id }}</guid>
+                               <title>{{ item.title }}</title>
+                               <link>http://www.ipfire.org/news/{{ item.slug }}</link>
+                               <author>{{ item.author.email }} ({{ item.author.cn }})</author>
+                               <guid>{{ item.uuid }}</guid>
                                <pubDate>{{ item.date }}</pubDate>
                                <description>
                                        <![CDATA[
-                                               {{ item.content }}
+                                               {{ item.text }}
                                        ]]>
                                </description>
                        </item>
index 386f4c23e4236ac14dd1d7445bf5ccff5b425a5b..705966e99bc9fb731d6e77021d1b043502468b99 100644 (file)
@@ -56,17 +56,17 @@ class Application(tornado.web.Application):
                        (r"/index\.?(s?html?)?", RootHandler),
 
                        # Handle news items
-                       #(r"/news/(.*)", NewsRedirectHandler),
                        (r"/news", NewsIndexHandler),
                        (r"/news/(.*)", NewsItemHandler),
                        (r"/author/(.*)", NewsAuthorHandler),
 
                        # Download sites
                        (r"/downloads?", DownloadHandler),
-#                      # RSS feed
-#                      (r"/([A-Za-z]{2})/news.rss", RSSHandler),
-#                      (r"/data/feeds/main-([A-Za-z]{2}).rss", RSSHandler),
 
+                       # RSS feed
+                       (r"/news.rss", RSSHandler),
+
+                       # Redirection for bookmarks, etc.
                        (r"/(de|en)/(.*)", LangCompatHandler)
 
                ] + static_handlers + [
@@ -74,13 +74,6 @@ class Application(tornado.web.Application):
                        (r"/(.*)", StaticHandler),
                ])
 
-               # news.ipfire.org
-               #self.add_handlers(r"news\.ipfire\.org", [
-               #       (r"/", NewsIndexHandler),
-               #       (r"/news/(.*)", NewsItemHandler),
-               #       (r"/author/(.*)", NewsAuthorHandler),
-               #] + static_handlers)
-
                # downloads.ipfire.org
                self.add_handlers(r"downloads?\.ipfire\.org", [
                        (r"/", DownloadsIndexHandler),
@@ -186,9 +179,6 @@ class Application(tornado.web.Application):
 
        def run(self, port=8001):
                logging.debug("Going to background")
-               
-               # All requests should be done after 30 seconds or they will be killed.
-               self.ioloop.set_blocking_log_threshold(30)
 
                http_server = tornado.httpserver.HTTPServer(self, xheaders=True)
 
@@ -199,6 +189,9 @@ class Application(tornado.web.Application):
                        http_server.start(num_processes=4)
                else:
                        http_server.listen(port)
+               
+               # All requests should be done after 30 seconds or they will be killed.
+               self.ioloop.set_blocking_log_threshold(30)
 
                self.ioloop.start()
 
index f0c3f8c85fc8eb287c19fa5e56600a1190cc6d2b..75b3d934e93ad57abfc0cadc2b6ae93e58e59f38 100644 (file)
@@ -21,11 +21,6 @@ class News(object):
                return self.db.get("SELECT * FROM news WHERE slug=%s", slug)
 
        def get_latest(self, author=None, locale=None, limit=1, offset=0):
-               # XXX find a better way to do offset
-
-               if offset:
-                       limit += offset
-
                query = "SELECT * FROM news WHERE published='Y'"
 
                if author:
@@ -37,14 +32,13 @@ class News(object):
                query += " ORDER BY date DESC"
 
                if limit:
-                       query += " LIMIT %d" % limit
+                       if offset:
+                               query += " LIMIT %d,%d" % (offset, limit)
+                       else:
+                               query += " LIMIT %d" % limit
 
                news = self.db.query(query)
 
-               # XXX can the database do this?
-               if offset:
-                       news = news[offset:]
-
                return news
 
 if __name__ == "__main__":
index afc4315b0090deb5f925010b3882f9259aadeb40..2a9c7590314f9088fdc79bed3fd5643b7a7787d8 100644 (file)
@@ -22,6 +22,7 @@ from handlers_iuse import *
 from handlers_mirrors import *
 from handlers_news import *
 from handlers_planet import *
+from handlers_rss import *
 from handlers_stasy import *
 from handlers_tracker import *
 
@@ -47,6 +48,8 @@ class LangCompatHandler(BaseHandler):
 
 
 class IndexHandler(BaseHandler):
+       rss_url = "/news.rss"
+
        """
                This handler displays the welcome page.
        """
index 15d795ca24ab6cd26c12aea27a58989cf9de81c1..109b378c697c34feffd870781ad1d8eae103dd42 100644 (file)
@@ -8,6 +8,8 @@ import tornado.web
 import backend
 
 class BaseHandler(tornado.web.RequestHandler):
+       rss_url = None
+
        def get_account(self, uid):
                # Find the name of the author
                return self.accounts.find(uid)
@@ -40,6 +42,7 @@ class BaseHandler(tornado.web.RequestHandler):
                return {
                        "hostname" : self.request.host,
                        "lang" : self.locale.code[:2],
+                       "rss_url" : self.rss_url,
                        "year" : time.strftime("%Y"),
                }
 
index acaf39ec309078ffa286e41f3c67c305e35a4b50..268d590d87fc98b6892d53472d63acdb21e10a82 100644 (file)
@@ -4,18 +4,9 @@ import tornado.web
 
 from handlers_base import *
 
-class NewsRedirectHandler(BaseHandler):
-       """
-               This handler redirects (with a given slug) to news.ipfire.org.
-
-               We do not show full news items on the main page and so need a simple
-               way to redirect. Here it is.
-       """
-       def get(self, slug):
-               self.redirect("http://news.ipfire.org/news/%s" % slug)
-
-
 class NewsIndexHandler(BaseHandler):
+       rss_url = "/news.rss"
+
        """
                This handler fetches the content that is show on the news portal.
        """
@@ -34,6 +25,8 @@ class NewsIndexHandler(BaseHandler):
 
 
 class NewsItemHandler(BaseHandler):
+       rss_url = "/news.rss"
+
        """
                This handler displays a whole page full of a single news item.
        """
@@ -63,7 +56,7 @@ class NewsAuthorHandler(BaseHandler):
                        raise tornado.web.HTTPError(404)
 
                latest_news = self.news.get_latest(author=author.uid,
-                       locale=self.locale, limit=3)
+                       locale=self.locale, limit=10)
 
                self.render("news-author.html",
                        author=author, latest_news=latest_news)
index fab4a3a62f5bb23e157a503ab4c0860557aeab6f..2105385df566ef8d868dc39ce590b7f95abda8bc 100644 (file)
@@ -2,6 +2,7 @@
 
 from __future__ import division
 
+import hashlib
 import logging
 import operator
 import socket
@@ -23,6 +24,10 @@ class UIModule(tornado.web.UIModule):
        def banners(self):
                return self.handler.banners
 
+       @property
+       def memcached(self):
+               return self.handler.memcached
+
        @property
        def releases(self):
                return self.handler.releases
@@ -67,7 +72,14 @@ class NewsItemModule(UIModule):
                        item.text = item.text[:400] + "..."
 
                # Render text
-               item.text = textile.textile(item.text)
+               text_id = "news-%s" % hashlib.md5(item.text.encode("utf-8")).hexdigest()
+
+               text = self.memcached.get(text_id)
+               if not text:
+                       text = textile.textile(item.text)
+                       self.memcached.set(text_id, text, 60)
+
+               item.text = text
 
                return self.render_string("modules/news-item.html", item=item, uncut=uncut)