@@ -60,16 +71,4 @@
{% end %}
-
- {% if not post.is_published() %}
-
- {% end %}
diff --git a/src/templates/blog/publish.html b/src/templates/blog/publish.html
new file mode 100644
index 00000000..fa29b18c
--- /dev/null
+++ b/src/templates/blog/publish.html
@@ -0,0 +1,48 @@
+{% extends "base.html" %}
+
+{% block title %}{{ _("Publish %s") % post.title }}{% end block %}
+
+{% block modal %}
+
+
+
{{ _("Publish Post") }}
+
{{ post.title }}
+
+
+
+
+{% end block %}
+
+{% block javascript %}
+
+{% end %}
diff --git a/src/web/blog.py b/src/web/blog.py
index d39ef396..ad770da7 100644
--- a/src/web/blog.py
+++ b/src/web/blog.py
@@ -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)
--
2.39.2