Skip to content

Instantly share code, notes, and snippets.

@raygunsix
Created April 14, 2010 17:09
Show Gist options
  • Save raygunsix/366065 to your computer and use it in GitHub Desktop.
Save raygunsix/366065 to your computer and use it in GitHub Desktop.
jsonified pylons index controller with search
def __before__(self):
self.q = Session.query(Keyphrases)
@jsonify
def index(self):
"""GET /keyphrases: All items in the collection"""
# url('keyphrases')
result = []
# If search terms are supplied in query string filter
# /keyphrases?search=fondue
if request.params:
kws = self.q.filter(Keyphrases.keyword.like('%' + request.params['search'] + '%'))
for kw in kws:
result.append(dict(id=kw.keyword_id, keyword=kw.keyword, source=kw.source))
return result
# Otherwise return all items
for kw in self.q:
result.append(dict(id=kw.keyword_id, keyword=kw.keyword, source=kw.source))
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment