def search(q): """ Implement search method with SQLAlchemy """ # Prepare query watches = session.query(Watch) if q: like_q = '%' + str(q) + '%' else: # Match nothing, return 0 results like_q = '' # Perform search results = watches.filter( or_( Watch.title.ilike(like_q), Watch.short_description.ilike(like_q), Watch.long_description.ilike(like_q), Watch.stk.ilike(like_q), ) ) # Make results serializable results = map(lambda r: r.as_dict(), results) return { 'count': len(results), 'results': results }
def get(self): feed = AtomFeed( 'Recently Added Watches - Wanna Buy A Watch', feed_url=request.url, url=request.url_root ) # Prepare query watches = session.query(Watch) # TODO: .limit(15) and date_added watches = watches.order_by(Watch.title).all() for watch in watches: feed.add( watch.title, unicode(watch.long_description), content_type='html', author='wbaw', url=BASE_URL + '/' + watch.page_url + '?src=wbawsearch', # TODO: Add updated and published updated=datetime.now(), published=datetime.now() ) return feed.get_response()
def get(self, id=None): # Prepare query watches = session.query(Watch) if id: # Return the specific watch results = watches.get(id) # Make results serializable results = results.as_dict() if results else {} else: # Return them all results = watches.order_by(Watch.pk).all() results = { 'count': len(results), 'results': map(lambda r: r.as_dict(), results) } return jsonify(results)
def get(self): feed = RssFeed( title='Recently Added Watches - Wanna Buy A Watch', link=request.url, description='Recently Added Watches - Wanna Buy A Watch', author="wbaw" ) # Prepare query watches = session.query(Watch) # TODO: .limit(15) and date_added watches = watches.order_by(Watch.title).all() for watch in watches: feed.add( title=watch.title, link=BASE_URL + '/' + watch.page_url + '?src=wbawsearch', description=unicode(watch.long_description), ) return feed.get_response()