diff --git a/scribeengine/controllers/post.py b/scribeengine/controllers/post.py index 0fce1ae..d0c5bf6 100644 --- a/scribeengine/controllers/post.py +++ b/scribeengine/controllers/post.py @@ -68,7 +68,10 @@ class PostController(BaseController): post.modified = datetime.now() post.title = c.form_values[u'title'] post.body = c.form_values[u'body'] - post.status = u'published' + if c.form_values[u'action'] == u'Save Draft': + post.status = u'draft' + else: + post.status = u'published' post.url = url tags = c.form_values[u'tags'] tag_list = [tag_name.strip() for tag_name in tags.split(u',')] @@ -82,5 +85,26 @@ class PostController(BaseController): post.tags.append(Tag(name=tag, url=utils.generate_url(tag))) Session.add(post) Session.commit() - h.redirect_to(str('/archive/%s/%s' % (post.created.strftime('%Y/%m/%d'), post.url))) + if c.form_values[u'action'] == u'Save Draft': + h.redirect_to(h.url_for(action=u'draft')) + else: + h.redirect_to(str('/archive/%s/%s' % (post.created.strftime('%Y/%m/%d'), post.url))) + + def draft(self): + posts = Session.query(Post)\ + .filter_by(status=u'draft')\ + .order_by(Post.created.desc()) + pagination = utils.paginate(posts, 10, + int(request.GET.get(u'page', 1)), '/') + c.posts = pagination[u'records'] + if pagination[u'prev'] != pagination[u'page']: + c.first_page = pagination[u'first'] + c.prev_page = pagination[u'prev'] + if pagination[u'next'] != pagination[u'page']: + c.next_page = pagination[u'next'] + c.last_page = pagination[u'last'] + c.list_start = pagination[u'start'] + c.list_total = pagination[u'total'] + c.list_end = pagination[u'end'] + return render(u'/post/draft.mako') diff --git a/scribeengine/templates/base.mako b/scribeengine/templates/base.mako index c5c7a5b..0d0b845 100644 --- a/scribeengine/templates/base.mako +++ b/scribeengine/templates/base.mako @@ -33,6 +33,7 @@ % if c.current_user: % if c.current_user.has_permission('Add Posts'):