Created
April 14, 2010 17:09
-
-
Save raygunsix/366065 to your computer and use it in GitHub Desktop.
jsonified pylons index controller with search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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