Merged in Edit Post and Draft functionality.
This commit is contained in:
commit
169ded4bdf
@ -50,6 +50,10 @@ class PostController(BaseController):
|
|||||||
if id is None:
|
if id is None:
|
||||||
h.redirect_to('/post/new')
|
h.redirect_to('/post/new')
|
||||||
c.post = Session.query(Post).get(id)
|
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
|
c.page_title = 'Edit Post: %s' % c.post.title
|
||||||
return render(u'/post/edit.mako')
|
return render(u'/post/edit.mako')
|
||||||
|
|
||||||
@ -64,7 +68,10 @@ class PostController(BaseController):
|
|||||||
post.modified = datetime.now()
|
post.modified = datetime.now()
|
||||||
post.title = c.form_values[u'title']
|
post.title = c.form_values[u'title']
|
||||||
post.body = c.form_values[u'body']
|
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
|
post.url = url
|
||||||
tags = c.form_values[u'tags']
|
tags = c.form_values[u'tags']
|
||||||
tag_list = [tag_name.strip() for tag_name in tags.split(u',')]
|
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)))
|
post.tags.append(Tag(name=tag, url=utils.generate_url(tag)))
|
||||||
Session.add(post)
|
Session.add(post)
|
||||||
Session.commit()
|
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')
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
% if c.current_user:
|
% if c.current_user:
|
||||||
% if c.current_user.has_permission('Add Posts'):
|
% if c.current_user.has_permission('Add Posts'):
|
||||||
<li><a href="${h.url_for(controller='post', action='new')}">New Post</a></li>
|
<li><a href="${h.url_for(controller='post', action='new')}">New Post</a></li>
|
||||||
|
<li><a href="${h.url_for(controller='post', action='draft')}">Draft Posts</a></li>
|
||||||
% endif
|
% endif
|
||||||
<li><a href="${h.url_for(controller='admin', action='logout')}">Logout</a></li>
|
<li><a href="${h.url_for(controller='admin', action='logout')}">Logout</a></li>
|
||||||
<li>Logged in as <em>${c.current_user.nick}</em></li>
|
<li>Logged in as <em>${c.current_user.nick}</em></li>
|
||||||
|
@ -8,14 +8,19 @@
|
|||||||
${h.literal(h.teaser(post.body))}
|
${h.literal(h.teaser(post.body))}
|
||||||
</div>
|
</div>
|
||||||
<p class="meta">
|
<p class="meta">
|
||||||
<span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span>
|
<span class="byline">
|
||||||
<a href="${h.url_for_post(post)}" class="read-more">Read more</a>
|
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'):
|
||||||
|
[<a href="${h.url_for(controller=u'post', action=u'edit', id=post.id)}">Edit</a>]
|
||||||
|
% endif
|
||||||
|
</span>
|
||||||
|
<a href="${h.url_for_post(post)}" class="read-more">Read more</a>
|
||||||
% if len(post.comments) == 0:
|
% if len(post.comments) == 0:
|
||||||
<a href="${h.url_for_post(post)}#comments" class="comments">No comments</a>
|
<a href="${h.url_for_post(post)}#comments" class="comments">No comments</a>
|
||||||
% elif len(post.comments) == 1:
|
% elif len(post.comments) == 1:
|
||||||
<a href="${h.url_for_post(post)}#comments" class="comments">1 comment</a>
|
<a href="${h.url_for_post(post)}#comments" class="comments">1 comment</a>
|
||||||
% else:
|
% else:
|
||||||
<a href="${h.url_for_post(post)}#comments" class="comments">${len(post.comments)} comments</a>
|
<a href="${h.url_for_post(post)}#comments" class="comments">${len(post.comments)} comments</a>
|
||||||
% endif
|
% endif
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,7 +2,12 @@
|
|||||||
<%include file="/flash.mako"/>
|
<%include file="/flash.mako"/>
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<h2 class="title">${c.post.title}</h2>
|
<h2 class="title">${c.post.title}</h2>
|
||||||
<div class="info">Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}</div>
|
<div class="info">
|
||||||
|
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'):
|
||||||
|
[<a href="${h.url_for(controller=u'post', action=u'edit', id=c.post.id)}">Edit</a>]
|
||||||
|
% endif
|
||||||
|
</div>
|
||||||
<div class="entry">
|
<div class="entry">
|
||||||
${h.literal(c.post.body)}
|
${h.literal(c.post.body)}
|
||||||
</div>
|
</div>
|
||||||
|
15
scribeengine/templates/post/draft.mako
Normal file
15
scribeengine/templates/post/draft.mako
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<%inherit file="/base.mako"/>
|
||||||
|
<%include file="/flash.mako"/>
|
||||||
|
<h2 class="title">Unpublished blog posts</h2>
|
||||||
|
% for post in c.posts:
|
||||||
|
<div class="post">
|
||||||
|
<h3 class="title"><a href="${h.url_for(controller=u'post', action=u'edit', id=post.id)}">${post.title}</a></h3>
|
||||||
|
<div class="entry">
|
||||||
|
${h.literal(h.teaser(post.body))}
|
||||||
|
</div>
|
||||||
|
<p class="meta">
|
||||||
|
<span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span>
|
||||||
|
<a href="${h.url_for(controller=u'post', action=u'edit', id=post.id)}" class="read-more">Edit post</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
% endfor
|
@ -18,8 +18,12 @@
|
|||||||
<input type="text" name="tags" id="post-tags" class="form-text" value="${c.post.tags_list}" />
|
<input type="text" name="tags" id="post-tags" class="form-text" value="${c.post.tags_list}" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<input type="submit" name="action" value="Save Draft"/>
|
% if c.post.status == u'published':
|
||||||
<input type="submit" name="action" value="Save & Publish"/>
|
<input type="submit" name="action" value="Save" class="form-button"/>
|
||||||
|
% else:
|
||||||
|
<input type="submit" name="action" value="Save Draft" class="form-button"/>
|
||||||
|
<input type="submit" name="action" value="Save & Publish" class="form-button"/>
|
||||||
|
% endif
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
Reference in New Issue
Block a user