From 12d2a966268f60277aab8cbda053c23f420e87ed Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 17 Feb 2010 23:10:21 +0200 Subject: [PATCH] Added very basic searching. --- scribeengine/controllers/blog.py | 18 ++++++++++++++++++ scribeengine/templates/blog/search.mako | 22 ++++++++++++++++++++++ scribeengine/templates/sidebar.mako | 6 +++--- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 scribeengine/templates/blog/search.mako diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py index 6ff585a..1de9482 100644 --- a/scribeengine/controllers/blog.py +++ b/scribeengine/controllers/blog.py @@ -23,6 +23,8 @@ import logging from datetime import datetime +from sqlalchemy.sql import or_ + from scribeengine.lib.base import * from scribeengine.lib import utils from scribeengine.model import Post, Comment, Tag @@ -111,3 +113,19 @@ class BlogController(BaseController): h.flash.set_message(u'Successfully submitted your comment.', u'success') h.redirect_to(h.url_for_post(post)) + def search(self): + c.querystring = request.GET.get(u'q') + if not c.querystring: + h.flash.set_message(u'You didn\'t supply anything to search for.', u'error') + h.redirect_to('/') + c.page_title = u'Search' + c.posts = Session.query(Post)\ + .filter( + or_( + Post.body.contains(c.querystring), + Post.title.contains(c.querystring) + ) + )\ + .all() + return render(u'/blog/search.mako') + diff --git a/scribeengine/templates/blog/search.mako b/scribeengine/templates/blog/search.mako new file mode 100644 index 0000000..363dfa1 --- /dev/null +++ b/scribeengine/templates/blog/search.mako @@ -0,0 +1,22 @@ +<%inherit file="/base.mako"/> + <%include file="/flash.mako"/> +

Searching for: "${c.querystring}"

+% for post in c.posts: +
+

${post.title}

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

+ + Read more +% if len(post.comments) == 0: + No comments +% elif len(post.comments) == 1: + 1 comment +% else: + ${len(post.comments)} comments +% endif +

+
+% endfor diff --git a/scribeengine/templates/sidebar.mako b/scribeengine/templates/sidebar.mako index 5dfded6..5e546c0 100644 --- a/scribeengine/templates/sidebar.mako +++ b/scribeengine/templates/sidebar.mako @@ -1,11 +1,11 @@