From: Michael Tremer Date: Sun, 29 Mar 2015 22:39:55 +0000 (+0200) Subject: planet: Add a view counter for the posts X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0c5565619c0163cdeea4a0694e48bb1ee1e0b54;p=ipfire.org.git planet: Add a view counter for the posts --- diff --git a/webapp/backend/planet.py b/webapp/backend/planet.py index 5beb90ff..c4f43207 100644 --- a/webapp/backend/planet.py +++ b/webapp/backend/planet.py @@ -115,6 +115,9 @@ class PlanetEntry(Object): def is_published(self): return self.status == "published" + def increase_view_counter(self): + self.db.execute("UPDATE planet SET views = views + 1 WHERE id = %s", self.id) + class Planet(Object): def get_authors(self): diff --git a/webapp/handlers_planet.py b/webapp/handlers_planet.py index 162359e9..cd8cf348 100644 --- a/webapp/handlers_planet.py +++ b/webapp/handlers_planet.py @@ -43,6 +43,9 @@ class PlanetPostingHandler(PlanetBaseHandler): if not entry: raise tornado.web.HTTPError(404) + # Update the view counter + entry.increase_view_counter() + self.render("planet/posting.html", author=entry.author, entry=entry)