diff --git a/scribeengine/controllers/post.py b/scribeengine/controllers/post.py index 447fa94..d0c5bf6 100644 --- a/scribeengine/controllers/post.py +++ b/scribeengine/controllers/post.py @@ -50,6 +50,10 @@ class PostController(BaseController): if id is None: h.redirect_to('/post/new') c.post = Session.query(Post).get(id) + if len(c.post.tags): + c.post.tags_list = u', '.join([tag.name for tag in c.post.tags]) + else: + c.post.tags_list = u'' c.page_title = 'Edit Post: %s' % c.post.title return render(u'/post/edit.mako') @@ -64,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',')] @@ -78,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'):
  • New Post
  • +
  • Draft Posts
  • % endif
  • Logout
  • Logged in as ${c.current_user.nick}
  • diff --git a/scribeengine/templates/blog/index.mako b/scribeengine/templates/blog/index.mako index 27c0921..ebbb6a4 100644 --- a/scribeengine/templates/blog/index.mako +++ b/scribeengine/templates/blog/index.mako @@ -8,14 +8,19 @@ ${h.literal(h.teaser(post.body))}

    - Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')} - Read more + + Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')} +% if c.current_user and c.current_user.id == post.user.id and c.current_user.has_permission(u'Edit My Posts'): + [Edit] +% endif + + Read more % if len(post.comments) == 0: - No comments + No comments % elif len(post.comments) == 1: - 1 comment + 1 comment % else: - ${len(post.comments)} comments + ${len(post.comments)} comments % endif

    diff --git a/scribeengine/templates/blog/view.mako b/scribeengine/templates/blog/view.mako index ae83e33..2c8dfaf 100644 --- a/scribeengine/templates/blog/view.mako +++ b/scribeengine/templates/blog/view.mako @@ -2,7 +2,12 @@ <%include file="/flash.mako"/>

    ${c.post.title}

    -
    Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}
    +
    + Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')} +% if c.current_user and c.current_user.id == c.post.user.id and c.current_user.has_permission(u'Edit My Posts'): + [Edit] +% endif +
    ${h.literal(c.post.body)}
    diff --git a/scribeengine/templates/post/draft.mako b/scribeengine/templates/post/draft.mako new file mode 100644 index 0000000..4177997 --- /dev/null +++ b/scribeengine/templates/post/draft.mako @@ -0,0 +1,15 @@ +<%inherit file="/base.mako"/> + <%include file="/flash.mako"/> +

    Unpublished blog posts

    +% for post in c.posts: +
    +

    ${post.title}

    +
    + ${h.literal(h.teaser(post.body))} +
    +

    + + Edit post +

    +
    +% endfor diff --git a/scribeengine/templates/post/edit.mako b/scribeengine/templates/post/edit.mako index 44006f1..8ac397a 100644 --- a/scribeengine/templates/post/edit.mako +++ b/scribeengine/templates/post/edit.mako @@ -18,8 +18,12 @@
    - - +% if c.post.status == u'published': + +% else: + + +% endif