Yesterday's changes.

This commit is contained in:
Raoul Snyman 2010-01-18 22:16:46 +02:00
parent df8bd84520
commit 7d4545a22e
8 changed files with 98 additions and 25 deletions

View File

@ -25,7 +25,7 @@ from datetime import datetime
from scribeengine.lib.base import *
from scribeengine.lib import utils
from scribeengine.model import Post
from scribeengine.model import Post, Comment
from scribeengine.model.meta import Session
log = logging.getLogger(__name__)
@ -70,3 +70,23 @@ class BlogController(BaseController):
.first()
c.page_title = c.post.title
return render(u'/blog/view.mako')
def comment_POST(self, id):
if not id:
h.flash.set_message(u'There was a problem submitting your comment.', u'error')
h.redirect_to('/')
post = Session.query(Post).get(id)
if not post or post.comment_status != u'open':
h.flash.set_message(u'There was a problem submitting your comment.', u'error')
h.redirect_to('/')
comment = Comment(
user = c.current_user,
title = c.form_values[u'title'],
body = c.form_values[u'body']
)
post.comments.append(comment)
Session.add(post)
Session.commit()
h.flash.set_message(u'Successfully submitted your comment.', u'success')
h.redirect_to(h.full_url(post))

View File

@ -78,4 +78,10 @@ def teaser(text, url):
text = text[:position]
return text
def full_url(post):
return '/archive/%s/%s/%s/%s' % (str(post.created.strftime('%Y')), \
str(post.created.strftime('%m')), \
str(post.created.strftime('%d')), \
str(post.url))
flash = Flash()

View File

@ -46,7 +46,7 @@ mapper(Permission, permissions_table)
mapper(Post, posts_table,
properties={
u'categories': relation(Category, backref='posts', secondary=categories_posts_table),
u'comments': relation(Comment, backref=u'post'),
u'comments': relation(Comment, backref=u'post', order_by=Comment.created.desc()),
u'tags': relation(Tag, backref=u'posts', secondary=posts_tags_table)
}
)

View File

@ -32,7 +32,7 @@ h3 {
font-size: 1em;
}
p, ul, ol {
p, ul, ol, pre {
margin-top: 1.8em;
line-height: 180%;
}
@ -186,6 +186,44 @@ hr {
margin-left: 1em;
}
.post pre {
background-color: #191919;
border: 1px solid #333333;
font-family: Monaco, Lucida Typewriter, Courier New, monospace;
margin-bottom: 0.5em;
padding: 0.3em 0.5em;
}
/* Comments */
#comments,
#respond {
font-size: 1.5em;
margin-top: 1.8em;
}
.commentlist {
font-weight: bold;
}
.commentlist li {
margin-top: 1em;
font-weight: normal;
}
.comment-title {
font-size: 1.2em;
font-weight: bold;
}
.comment-meta {
font-size: 0.9em;
}
.user-details {
margin-top: 0;
}
/* Sidebar */
#sidebar {
@ -319,7 +357,7 @@ fieldset {
.form-textarea {
height: 12em;
width: 605px;
width: 595px;
}
.form-button {

View File

@ -19,6 +19,11 @@
% for page in c.pages:
<li><a href="${page.url}">${page.name}</a></li>
% endfor
% if c.current_user:
<li><a href="${h.url_for('/admin/logout')}">Logout</a></li>
% else:
<li><a href="${h.url_for('/admin/login')}">Login</a></li>
% endif
</ul>
</div>
<hr />

View File

@ -1,21 +1,20 @@
<%inherit file="/base.mako"/>
<%include file="/flash.mako"/>
% for post in c.posts:
<% post.full_url = u'/archive/%s/%s/%s/%s' % (post.created.strftime('%Y'), post.created.strftime('%m'), post.created.strftime('%d'), post.url) %>
<div class="post">
<h2 class="title"><a href="${post.full_url}">${post.title}</a></h2>
<h2 class="title"><a href="${h.full_url(post)}">${post.title}</a></h2>
<div class="entry">
${h.literal(h.teaser(post.body, post.full_url))}
${h.literal(h.teaser(post.body, h.full_url(post)))}
</div>
<p class="meta">
<span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span>
<a href="${post.full_url}" class="read-more">Read more</a>
<a href="${h.full_url(post)}" class="read-more">Read more</a>
% if len(post.comments) == 0:
<a href="${post.full_url}#comments" class="comments">No comments</a>
<a href="${h.full_url(post)}#comments" class="comments">No comments</a>
% elif len(post.comments) == 1:
<a href="${post.full_url}#comments" class="comments">1 comment</a>
<a href="${h.full_url(post)}#comments" class="comments">1 comment</a>
% else:
<a href="${post.full_url}#comments" class="comments">${len(post.comments)} comments</a>
<a href="${h.full_url(post)}#comments" class="comments">${len(post.comments)} comments</a>
% endif
</p>
</div>

View File

@ -1,15 +1,13 @@
<%inherit file="/base.mako"/>
<div class="post">
<%include file="/flash.mako"/>
<h2 class="title"><a href="${h.url_for(year=c.post.created.strftime('%Y'), month=c.post.created.strftime('%m'), day=c.post.created.strftime('%d'), url=c.post.url)}">${c.post.title}</a></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>
<%include file="/flash.mako"/>
<div class="entry">
${h.literal(c.post.body)}
</div>
<div>&nbsp;</div>
% if len(c.post.comments) == 0:
<h3 id="comments">No Responses</h3>
<p>&nbsp;</p>
% elif len(c.post.comments) == 1:
<h3 id="comments">One Response</h3>
% else:
@ -19,9 +17,16 @@
<ol class="commentlist">
% for num, comment in enumerate(c.post.comments):
<li id="comment-${comment.id}">
<cite>${comment.user.nick}</cite> Says:<br />
<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title="">${comment.created.strftime('%B %d, %Y')} at ${comment.created.strftime('%H:%M')}</a> <a href="edit">edit</a></small>
${comment.body}
<div class="comment-title">
<a href="#comment-${comment.id}" title="${comment.title}">${comment.title}</a>
</div>
<div class="comment-meta">
by <cite>${comment.user.nick}</cite>
on ${comment.created.strftime('%B %d, %Y')} at ${comment.created.strftime('%H:%M')}
</div>
<div>
${comment.body}
</div>
</li>
% endfor
</ol>
@ -33,15 +38,14 @@
% if c.post.comment_status == u'open':
<h3 id="respond">Leave a Reply</h3>
% if not c.current_user:
<p>You must be <a href="/login">logged in</a> to post a comment.</p>
<p>You must be <a href="${h.url_for('/admin/login')}">logged in</a> to post a comment.</p>
% else:
<div>&nbsp;</div>
<form action="${h.url_for('/comment/edit')}" method="post" id="commentform">
<p>Logged in as <em>${c.current_user.nick}</em>. <a href="/logout" title="Log out of this account">Logout &raquo;</a></p>
<p><textarea name="comment" id="comment" cols="80" rows="10" tabindex="4" style="width: 605px;"></textarea></p>
<form action="${h.url_for('/blog/comment/%s' % c.post.id)}" method="post" id="commentform">
<p class="user-details">Logged in as <em>${c.current_user.nick}</em>. <a href="/logout" title="Log out of this account">Logout &raquo;</a></p>
<p><input type="text" name="title" class="form-text" value="RE: ${c.post.title}" /></p>
<p><textarea name="body" class="form-textarea" cols="80" rows="10" tabindex="4"></textarea></p>
<p>
<input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<input type="hidden" name="post_id" value="${c.post.id}" />
<input name="submit" type="submit" id="submit" tabindex="5" class="form-button" value="Submit Comment" />
</p>
</form>
% endif

View File

@ -15,6 +15,7 @@ setup(
install_requires=[
"Pylons>=0.9.7",
"SQLAlchemy>=0.5",
"TurboMail>=3.0"
],
setup_requires=["PasteScript>=1.6.3"],
packages=find_packages(exclude=['ez_setup']),