]> git.ipfire.org Git - ipfire.org.git/commitdiff
Drop planet from backend
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Jul 2018 18:33:31 +0000 (19:33 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Jul 2018 18:33:31 +0000 (19:33 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/base.py
src/backend/planet.py [deleted file]
src/templates/index.html
src/web/handlers.py
src/web/handlers_base.py
src/web/handlers_rss.py

index 9a403faba6dea19b3f8086382560baa62bf2937a..94b9de0f4080f85ceefab07746a86d95cd149616 100644 (file)
@@ -14,7 +14,6 @@ import mirrors
 import netboot
 import nopaste
 import news
-import planet
 import releases
 import settings
 import talk
@@ -57,7 +56,6 @@ class Backend(object):
                self.netboot = netboot.NetBoot(self)
                self.nopaste = nopaste.Nopaste(self)
                self.news = news.News(self)
-               self.planet = planet.Planet(self)
                self.releases = releases.Releases(self)
                self.talk = talk.Talk(self)
 
diff --git a/src/backend/planet.py b/src/backend/planet.py
deleted file mode 100644 (file)
index c6b3582..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-#!/usr/bin/python
-
-import datetime
-import re
-import textile
-import unicodedata
-
-from misc import Object
-
-class PlanetEntry(Object):
-       def __init__(self, backend, data):
-               Object.__init__(self, backend)
-
-               self.data = data
-
-       def __cmp__(self, other):
-               return cmp(self.published, other.published)
-
-       @property
-       def id(self):
-               return self.data.id
-
-       @property
-       def slug(self):
-               return self.data.slug
-
-       def set_title(self, title):
-               if self.title == title:
-                       return
-
-               self.db.execute("UPDATE planet SET title = %s WHERE id = %s", title, self.id)
-               self.data["title"] = title
-
-       title = property(lambda s: s.data.title, set_title)
-
-       @property
-       def url(self):
-               return "https://planet.ipfire.org/post/%s" % self.slug
-
-       def set_published(self, published):
-               if self.published == published:
-                       return
-
-               self.db.execute("UPDATE planet SET published = %s WHERE id = %s",
-                       published, self.id)
-               self.data["published"] = published
-
-       published = property(lambda s: s.data.published, set_published)
-
-       @property
-       def year(self):
-               return self.published.year
-
-       @property
-       def month(self):
-               return self.published.month
-
-       @property
-       def updated(self):
-               return self.data.updated
-
-       def get_markdown(self):
-               return self.data.markdown
-
-       def set_markdown(self, markdown):
-               if self.markdown == markdown:
-                       return
-
-               markup = self.render(markdown)
-               self.db.execute("UPDATE planet SET markdown = %s, markup = %s WHERE id = %s",
-                       markdown, markup, self.id)
-
-               self.data.update({
-                       "markdown" : markdown,
-                       "markup"   : markup,
-               })
-
-       markdown = property(get_markdown, set_markdown)
-
-       @property
-       def markup(self):
-               if self.data.markup:
-                       return self.data.markup
-
-               return self.render(self.markdown)
-
-       @property
-       def abstract(self):
-               return self.render(self.markdown, 400)
-
-       def render(self, text, limit=0):
-               return self.planet.render(text, limit)
-
-       @property
-       def text(self):
-               # Compat for markup
-               return self.markup
-
-       @property
-       def author(self):
-               if not hasattr(self, "_author"):
-                       self._author = self.accounts.get_by_uid(self.data.author_id)
-
-               return self._author
-
-       def set_status(self, status):
-               if self.status == status:
-                       return
-
-               self.db.execute("UPDATE planet SET status = %s WHERE id = %s", status, self.id)
-               self.data["status"] = status
-
-       status = property(lambda s: s.data.status, set_status)
-
-       def is_draft(self):
-               return self.status == "draft"
-
-       def is_published(self):
-               return self.status == "published"
-
-       def count_view(self, referer=None, location=None):
-               self.db.execute("INSERT INTO planet_views(post_id, referer, location) \
-                       VALUES(%s, %s, %s)", self.id, referer, location)
-
-               if hasattr(self, "_views"):
-                       self._views += 1
-
-       @property
-       def views(self):
-               if not hasattr(self, "_views"):
-                       res = self.db.get("SELECT COUNT(*) AS views FROM planet_views \
-                               WHERE post_id = %s", self.id)
-
-                       self._views = res.views
-
-               return self._views
-
-
-class Planet(Object):
-       def get_authors(self):
-               query = self.db.query("SELECT DISTINCT author_id FROM planet WHERE status = %s \
-                       AND published IS NOT NULL AND published <= NOW()", "published")
-
-               authors = []
-               for author in query:
-                       author = self.accounts.search(author.author_id)
-                       if author:
-                               authors.append(author)
-
-               return sorted(authors)
-
-       def get_years(self):
-               res = self.db.query("SELECT DISTINCT EXTRACT(YEAR FROM published)::integer AS year \
-                       FROM planet WHERE status = %s ORDER BY year DESC", "published")
-
-               return [row.year for row in res]
-
-       def get_entry_by_slug(self, slug):
-               entry = self.db.get("SELECT * FROM planet WHERE slug = %s", slug)
-
-               if entry:
-                       return PlanetEntry(self.backend, entry)
-
-       def get_entry_by_id(self, id):
-               entry = self.db.get("SELECT * FROM planet WHERE id = %s", id)
-
-               if entry:
-                       return PlanetEntry(self.backend, entry)
-
-       def get_entries(self, limit=3, offset=None, status="published", author_id=None):
-               query = "SELECT * FROM planet"
-               args, clauses = [], []
-
-               if status:
-                       clauses.append("status = %s")
-                       args.append(status)
-
-                       if status == "published":
-                               clauses.append("published <= NOW()")
-
-               if author_id:
-                       clauses.append("author_id = %s")
-                       args.append(author_id)
-
-               if clauses:
-                       query += " WHERE %s" % " AND ".join(clauses)
-
-               query += " ORDER BY published DESC"
-
-               # Respect limit and offset
-               if limit:
-                       query += " LIMIT %s"
-                       args.append(limit)
-
-                       if offset:
-                               query += " OFFSET %s"
-                               args.append(offset)
-
-               entries = []
-               for entry in self.db.query(query, *args):
-                       entry = PlanetEntry(self.backend, entry)
-                       entries.append(entry)
-
-               return entries
-
-       def get_entries_by_author(self, author_id, limit=None, offset=None):
-               return self.get_entries(limit=limit, offset=offset, author_id=author_id)
-
-       def get_entries_by_year(self, year):
-               entries = self.db.query("SELECT * FROM planet \
-                       WHERE status = %s AND EXTRACT(YEAR FROM published) = %s \
-                       ORDER BY published DESC", "published", year)
-
-               return [PlanetEntry(self.backend, e) for e in entries]
-
-       def get_hot_entries(self, days=30, limit=8):
-               entries = self.db.query("WITH hottest AS (SELECT post_id, COUNT(post_id) AS count \
-                       FROM planet_views WHERE \"when\" >= NOW() - INTERVAL '%s days' \
-                       GROUP BY post_id ORDER BY count DESC) SELECT * FROM planet \
-                       LEFT JOIN hottest ON planet.id = hottest.post_id \
-                       WHERE hottest.count IS NOT NULL \
-                       ORDER BY hottest.count DESC LIMIT %s",
-                       days, limit)
-
-               return [PlanetEntry(self.backend, e) for e in entries]
-
-       def render(self, text, limit=0):
-               if limit and len(text) >= limit:
-                       text = text[:limit] + "..."
-
-               return textile.textile(text)
-
-       def _generate_slug(self, title):
-               slug = unicodedata.normalize("NFKD", title).encode("ascii", "ignore")
-               slug = re.sub(r"[^\w]+", " ", slug)
-               slug = "-".join(slug.lower().strip().split())
-
-               if not slug:
-                       slug = "entry"
-
-               while True:
-                       e = self.db.get("SELECT * FROM planet WHERE slug = %s", slug)
-                       if not e:
-                               break
-                       slug += "-"
-
-               return slug
-
-       def create(self, title, markdown, author, status="published", published=None):
-               slug = self._generate_slug(title)
-               markup = self.render(markdown)
-
-               if published is None:
-                       published = datetime.datetime.utcnow()
-
-               id = self.db.execute("INSERT INTO planet(author_id, slug, title, status, \
-                       markdown, markup, published) VALUES(%s, %s, %s, %s, %s, %s, %s) RETURNING id",
-                       author.uid, slug, title, status, markdown, markup, published)
-
-               if id:
-                       return self.get_entry_by_id(id)
-
-       def update_entry(self, entry):
-               self.db.execute("UPDATE planet SET title = %s, markdown = %s WHERE id = %s",
-                       entry.title, entry.markdown, entry.id)
-
-       def save_entry(self, entry):
-               slug = self._generate_slug(entry.title)
-
-               id = self.db.execute("INSERT INTO planet(author_id, title, slug, markdown, published) \
-                       VALUES(%s, %s, %s, %s, NOW())", entry.author.uid, entry.title, slug, entry.markdown)
-
-               return id
-
-       def search(self, what):
-               res = self.db.query("WITH \
-                       q      AS (SELECT plainto_tsquery(%s, %s) AS query), \
-                       ranked AS (SELECT id, query, ts_rank_cd(to_tsvector(%s, markdown), query) AS rank \
-                               FROM planet, q WHERE markdown @@ query ORDER BY rank DESC) \
-                       SELECT *, ts_headline(markup, ranked.query, 'MinWords=100, MaxWords=110') AS markup FROM planet \
-                               JOIN ranked ON planet.id = ranked.id \
-                               WHERE status = %s AND published IS NOT NULL AND published <= NOW() \
-                               ORDER BY ranked DESC LIMIT 25",
-                       "english", what, "english", "published")
-
-               return [PlanetEntry(self.backend, e) for e in res]
index 4e72a65007f63b95a73f7cca316008b995db6170..5cb1db17b42a039404642c3d32918e727865fea3 100644 (file)
                                                <h1>What&rsquo;s going on?</h1>
 
                                                <dl class="dl-horizontal">
-                                                       {% for type, item in latest_news %}
+                                                       {% for post in posts %}
                                                                <dt>
-                                                                       <small>{{ locale.format_date(item.published, relative=True, shorter=True) }} &nbsp;</small>
+                                                                       <small>{{ locale.format_date(item.published_at, relative=True, shorter=True) }} &nbsp;</small>
                                                                </dt>
 
                                                                <dd class="text-overflow mb-4">
-                                                                       {% if type == "news" %}
-                                                                               <a href="/news/{{ item.slug }}">
-                                                                                       <strong>{{ item.title }}</strong>
-                                                                               </a>
-                                                                       {% elif type == "planet" %}
-                                                                               <a href="https://planet.ipfire.org/post/{{ item.slug }}">
-                                                                                       {{ item.title }}
-                                                                               </a>
-                                                                       {% end %}
+                                                                       <a href="https://blog.ipfire.org/post/{{ post.slug }}">{{ post.title }}</a>
                                                                </dd>
                                                        {% end %}
                                                </dl>
index a38690c938994b00cf760d34a6c5ab41f79db098..f414a1adf9917487d5e5672768d6e7c1da226eb4 100644 (file)
@@ -48,27 +48,13 @@ class IndexHandler(BaseHandler):
                # Get the latest release.
                latest_release = self.releases.get_latest()
 
-               # Get a list of the most recent news items and put them on the page.            
-               latest_news = self.get_latest_news()
+               # Get a list of the most recent news items and put them on the page.
+               posts = self.backend.blog.get_newest(limit=5)
 
-               return self.render("index.html", latest_news=latest_news,
+               return self.render("index.html", posts=posts,
                        latest_release=latest_release,
                        fireinfo_country=self.fireinfo.get_random_country_penetration())
 
-       def get_latest_news(self, count=5):
-               latest_news = []
-
-               for news in self.news.get_latest(limit=count):
-                       latest_news.append(("news", news))
-
-               for post in self.planet.get_entries(limit=count):
-                       latest_news.append(("planet", post))
-
-               latest_news.sort(key=operator.itemgetter(1), reverse=True)
-
-               return latest_news[:count]
-
-
 class GeoIPHandler(BaseHandler):
        def get_address(self):
                addr = self.get_argument("addr", None)
index 8bd4a83b33ab2c90723614791f0c8ea71bac9fad..a31823795dc834b38c13be010e00994185f64fc6 100644 (file)
@@ -214,10 +214,6 @@ class BaseHandler(tornado.web.RequestHandler):
        def tracker(self):
                return self.backend.tracker
 
-       @property
-       def planet(self):
-               return self.backend.planet
-
 
 class LoginHandler(BaseHandler):
        def get(self):
index 8d3257f957661c404d26a8c3ee6862bb79e91623..4899bf4d1e08b7e3ec5642b3277982c2a8bec160 100644 (file)
@@ -74,18 +74,3 @@ class RSSNewsHandler(RSSHandler):
                        items.append(item)
 
                return self.render_string("feeds/news.xml", items=items)
-
-
-class RSSPlanetAllHandler(RSSHandler):
-       def generate(self):
-               items = self.planet.get_entries(limit=self.limit, offset=self.offset)
-
-               return self.render_string("feeds/planet.xml", items=items)
-
-
-class RSSPlanetUserHandler(RSSPlanetAllHandler):
-       def generate(self, user):
-               items = self.planet.get_entries_by_author(user,
-                       limit=self.limit, offset=self.offset)
-
-               return self.render_string("feeds/planet.xml", items=items)