Added very basic searching.
This commit is contained in:
parent
cfad76f615
commit
12d2a96626
@ -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')
|
||||
|
||||
|
22
scribeengine/templates/blog/search.mako
Normal file
22
scribeengine/templates/blog/search.mako
Normal file
@ -0,0 +1,22 @@
|
||||
<%inherit file="/base.mako"/>
|
||||
<%include file="/flash.mako"/>
|
||||
<h2 class="title">Searching for: "${c.querystring}"</h2>
|
||||
% for post in c.posts:
|
||||
<div class="post">
|
||||
<h3 class="title"><a href="${h.url_for_post(post)}">${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_post(post)}" class="read-more">Read more</a>
|
||||
% if len(post.comments) == 0:
|
||||
<a href="${h.url_for_post(post)}#comments" class="comments">No comments</a>
|
||||
% elif len(post.comments) == 1:
|
||||
<a href="${h.url_for_post(post)}#comments" class="comments">1 comment</a>
|
||||
% else:
|
||||
<a href="${h.url_for_post(post)}#comments" class="comments">${len(post.comments)} comments</a>
|
||||
% endif
|
||||
</p>
|
||||
</div>
|
||||
% endfor
|
@ -1,11 +1,11 @@
|
||||
<div id="sidebar">
|
||||
<ul>
|
||||
<li id="search">
|
||||
<form id="searchform" method="get" action="/search">
|
||||
<form id="searchform" method="get" action="/blog/search">
|
||||
<div>
|
||||
<input type="text" name="keywords" id="s" size="15" />
|
||||
<input type="text" name="q" id="s" size="15" />
|
||||
<br />
|
||||
<input name="submit" type="submit" value="Search" />
|
||||
<input type="submit" value="Search" />
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
|
Reference in New Issue
Block a user