diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py index dca72f8..12b34e8 100644 --- a/scribeengine/controllers/blog.py +++ b/scribeengine/controllers/blog.py @@ -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)) + diff --git a/scribeengine/lib/helpers.py b/scribeengine/lib/helpers.py index 5b0a7f5..17f1403 100644 --- a/scribeengine/lib/helpers.py +++ b/scribeengine/lib/helpers.py @@ -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() diff --git a/scribeengine/model/__init__.py b/scribeengine/model/__init__.py index 46dee34..854ff67 100644 --- a/scribeengine/model/__init__.py +++ b/scribeengine/model/__init__.py @@ -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) } ) diff --git a/scribeengine/public/styles/style.css b/scribeengine/public/styles/style.css index b18b9e3..8adcc00 100644 --- a/scribeengine/public/styles/style.css +++ b/scribeengine/public/styles/style.css @@ -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 { diff --git a/scribeengine/templates/base.mako b/scribeengine/templates/base.mako index 532a870..6538cae 100644 --- a/scribeengine/templates/base.mako +++ b/scribeengine/templates/base.mako @@ -19,6 +19,11 @@ % for page in c.pages:
  • ${page.name}
  • % endfor +% if c.current_user: +
  • Logout
  • +% else: +
  • Login
  • +% endif
    diff --git a/scribeengine/templates/blog/index.mako b/scribeengine/templates/blog/index.mako index 7c57bbe..6b6a0d2 100644 --- a/scribeengine/templates/blog/index.mako +++ b/scribeengine/templates/blog/index.mako @@ -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) %>
    -

    ${post.title}

    +

    ${post.title}

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

    - Read more + 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 c8b5332..9fd18bd 100644 --- a/scribeengine/templates/blog/view.mako +++ b/scribeengine/templates/blog/view.mako @@ -1,15 +1,13 @@ <%inherit file="/base.mako"/>
    - <%include file="/flash.mako"/> -

    ${c.post.title}

    +

    ${c.post.title}

    Posted by ${c.post.user.nick} on ${c.post.created.strftime('%B %d, %Y')}
    + <%include file="/flash.mako"/>
    ${h.literal(c.post.body)}
    -
     
    % if len(c.post.comments) == 0:

    No Responses

    -

     

    % elif len(c.post.comments) == 1:

    One Response

    % else: @@ -19,9 +17,16 @@
      % for num, comment in enumerate(c.post.comments):
    1. - ${comment.user.nick} Says:
      - - ${comment.body} + +
      + by ${comment.user.nick} + on ${comment.created.strftime('%B %d, %Y')} at ${comment.created.strftime('%H:%M')} +
      +
      + ${comment.body} +
    2. % endfor
    @@ -33,15 +38,14 @@ % if c.post.comment_status == u'open':

    Leave a Reply

    % if not c.current_user: -

    You must be logged in to post a comment.

    +

    You must be logged in to post a comment.

    % else: -
     
    -
    -

    Logged in as ${c.current_user.nick}. Logout »

    -

    + +

    Logged in as ${c.current_user.nick}. Logout »

    +

    +

    - - +

    % endif diff --git a/setup.py b/setup.py index d53c50c..16176a5 100644 --- a/setup.py +++ b/setup.py @@ -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']),