]> git.ipfire.org Git - ipfire.org.git/blobdiff - webapp/handlers_admin.py
Huge update for fireinfo, introducting talk and nopaste
[ipfire.org.git] / webapp / handlers_admin.py
index 7c4cb1a1be8866e11f79db1a0a2d34bece46fb73..d7da2b528d48d390ffc5744531e38438cc489e27 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import datetime
 import tornado.web
 
 from handlers_base import *
@@ -7,43 +8,7 @@ from handlers_base import *
 import backend
 
 class AdminBaseHandler(BaseHandler):
-       @property
-       def accounts(self):
-               return backend.Accounts()
-
-       @property
-       def planet(self):
-               return backend.Planet()
-
-       @property
-       def downloads(self):
-               return backend.Downloads()
-
-       def get_current_user(self):
-               return self.get_secure_cookie("account")
-
-
-class AdminLoginHandler(AdminBaseHandler):
-       def get(self):
-               self.render("admin-login.html")
-
-       def post(self):
-               account = self.accounts.search(self.get_argument("name"))
-               if not account:
-                       raise tornado.web.HTTPError(403)
-
-               if account.check_password(self.get_argument("password")):
-                       self.set_secure_cookie("account", account.uid)
-               else:
-                       raise tornado.web.HTTPError(403)
-
-               self.redirect("/")
-
-
-class AdminLogoutHandler(AdminBaseHandler):
-       def get(self):
-               self.clear_cookie("account")
-               self.redirect("/")
+       pass
 
 
 class AdminIndexHandler(AdminBaseHandler):
@@ -61,51 +26,71 @@ class AdminApiPlanetRenderMarkupHandler(AdminBaseHandler):
                output = {
                        "html" : self.planet.render(text),
                }
-               self.write(output)
-               self.finish()
+               self.finish(output)
 
 
 class AdminPlanetHandler(AdminBaseHandler):
        @tornado.web.authenticated
        def get(self):
-               entries = self.planet.get_entries(limit=100)
+               entries = self.planet.get_entries(status=None, limit=50)
 
                self.render("admin-planet.html", entries=entries)
 
 
 class AdminPlanetComposeHandler(AdminBaseHandler):
        @tornado.web.authenticated
-       def get(self, id=None):
-               entry = backend.PlanetEntry()
+       def get(self, slug=None):
+               entry = None
 
-               if id:
-                       entry = self.planet.get_entry_by_id(id)
+               if slug:
+                       entry = self.planet.get_entry_by_slug(slug)
+                       if not entry:
+                               raise tornado.web.HTTPError(404)
 
                self.render("admin-planet-compose.html", entry=entry)
 
        @tornado.web.authenticated
-       def post(self, id=None):
-               id = self.get_argument("id", id)
-
-               entry = backend.PlanetEntry()
+       def post(self):
+               title = self.get_argument("title")
+               markdown = self.get_argument("markdown")
 
-               if id:
-                       entry = self.planet.get_entry_by_id(id)
+               status = self.get_argument("status", "draft")
+               assert status in ("draft", "published")
 
-               entry.set("title", self.get_argument("title"))
-               entry.set("markdown", self.get_argument("markdown"))
-               entry.set("author_id", self.current_user)
+               author = self.accounts.find(self.current_user)
 
-               if id:
-                       self.planet.update_entry(entry)
-               else:
-                       self.planet.save_entry(entry)
+               entry = self.planet.create(title=title, markdown=markdown,
+                       author=author, status=status)
 
                self.redirect("/planet")
 
 
 class AdminPlanetEditHandler(AdminPlanetComposeHandler):
-       pass
+       @tornado.web.authenticated
+       def post(self, slug):
+               entry = self.planet.get_entry_by_slug(slug)
+               if not entry:
+                       raise tornado.web.HTTPError(404)
+
+               entry.title = self.get_argument("title")
+               entry.markdown = self.get_argument("markdown")
+
+               entry.status = self.get_argument("status", "draft")
+
+               self.redirect("/planet")
+
+
+class AdminPlanetPublishHandler(AdminBaseHandler):
+       @tornado.web.authenticated
+       def get(self, slug):
+               entry = self.planet.get_entry_by_slug(slug)
+               if not entry:
+                       raise tornado.web.HTTPError(404)
+
+               entry.status = "published"
+               entry.published = datetime.datetime.utcnow()
+
+               self.redirect("/planet")
 
 
 class AdminAccountsBaseHandler(AdminBaseHandler):
@@ -141,15 +126,13 @@ class AdminAccountsDeleteHandler(AdminAccountsBaseHandler):
 
 
 class AdminMirrorsBaseHandler(AdminBaseHandler):
-       @property
-       def mirrors(self):
-               return backend.Mirrors()
+       pass
 
 
 class AdminMirrorsHandler(AdminMirrorsBaseHandler):
        @tornado.web.authenticated
        def get(self):
-               mirrors = self.mirrors.list()
+               mirrors = self.mirrors.get_all()
 
                self.render("admin-mirrors.html", mirrors=mirrors)
 
@@ -165,7 +148,7 @@ class AdminMirrorsCreateHandler(AdminMirrorsBaseHandler):
        @tornado.web.authenticated
        def get(self, id=None):
                if id:
-                       mirror = self.db.get("SELECT * FROM mirrors WHERE id = '%s'", int(id))
+                       mirror = self.db.get("SELECT * FROM mirrors WHERE id = %s", id)
                else:
                        mirror = tornado.database.Row(
                                id="",
@@ -244,7 +227,7 @@ class AdminNewsBaseHandler(AdminBaseHandler):
 class AdminNewsHandler(AdminNewsBaseHandler):
        @tornado.web.authenticated
        def get(self):
-               news = self.news.list()
+               news = self.news.get_all()
 
                self.render("admin-news.html", news=news)