]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/web/blog.py
blog: Add dialogue to publish posts at a certain time
[ipfire.org.git] / src / web / blog.py
index d39ef396446714328497f45457e40c2b329ebf4e..ad770da7ffca392c68d067c1f64b76a627f986da 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 import datetime
+import dateutil
 import email.utils
 import tornado.web
 
@@ -69,21 +70,43 @@ class PostHandler(auth.CacheMixin, base.BaseHandler):
 
 
 class PublishHandler(auth.CacheMixin, base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self, slug):
+               post = self.backend.blog.get_by_slug(slug, published=False)
+               if not post:
+                       raise tornado.web.HTTPError(404)
+
+               # Check if current_user is allowed to edit the post
+               if not post.is_editable(self.current_user):
+                       raise tornado.web.HTTPError(403)
+
+               # Is the post already published?
+               if post.is_published():
+                       raise tornado.web.HTTPError(400, "Post is already published")
+
+               self.render("blog/publish.html", post=post)
+
        @tornado.web.authenticated
        def post(self, slug):
-               post = self.backend.blog.get_by_slug(slug, published=not self.current_user)
+               post = self.backend.blog.get_by_slug(slug, published=False)
                if not post:
                        raise tornado.web.HTTPError(404)
 
+               # Check if current_user is allowed to edit the post
+               if not post.is_editable(self.current_user):
+                       raise tornado.web.HTTPError(403)
+
                # Is the post already published?
                if post.is_published():
                        raise tornado.web.HTTPError(400, "Post is already published")
 
-               # XXX Check that we are only publishing our own posts
+               when = self.get_argument("when", None)
+               if when:
+                       when = dateutil.parser.parse(when)
 
                # Publish the post
                with self.db.transaction():
-                       post.publish()
+                       post.publish(when)
 
                self.redirect("/post/%s" % post.slug)