]> git.ipfire.org Git - ipfire.org.git/blobdiff - webapp/backend/planet.py
Massive web site update
[ipfire.org.git] / webapp / backend / planet.py
index d116ced35610528550c61958cb9d0026281948ac..7f69b51c526396ecd00eb80781692149f0ea87e2 100644 (file)
@@ -13,6 +13,9 @@ class PlanetEntry(Object):
 
                self.data = data
 
+       def __cmp__(self, other):
+               return cmp(self.published, other.published)
+
        @property
        def id(self):
                return self.data.id
@@ -119,6 +122,19 @@ class PlanetEntry(Object):
                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):
@@ -264,7 +280,7 @@ class Planet(Object):
                        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 10",
+                               ORDER BY ranked DESC LIMIT 25",
                        "english", what, "english", "published")
 
                return [PlanetEntry(self.backend, e) for e in res]