def get(self, **kwargs): json = request.is_xhr or request.args.get('json', '') response = Response(mimetype = 'application/json' if json else 'text/html') collection = FilterCollection(filters, request, response) query = models.accepted_quotes() collection.add_to_query(query) query.filter('random >', random.random()) query.order('random') qs = [ q for q in query.fetch(_n) ] if len(qs) < _n: # wraparound! query = models.accepted_quotes() collection.add_to_query(query) query.order('random') qs.extend(query.fetch(_n - len(qs))) if len(qs) > 0: q = random.choice(qs) else: q = None if json: out = quotejson.single(q) else: out = render_template( 'cppbash/random_quote.html', quote = q, filter_collection = collection) response.response = [out] return response
def get(self, **kwargs): response = Response(mimetype = 'application/atom+xml') collection = FilterCollection(filters, request, response, cookies=False) q = models.accepted_quotes() collection.add_to_query(q) q.order('-creation_date') out = render_template( 'cppbash/atom.xml', title = "C++ Bash", link = url_for('home', full=True), quotes = q) response.response = [out] return response
def get(self, **kwargs): json = request.is_xhr or request.args.get('json', '') response = Response(mimetype = 'application/json' if json else 'text/html') collection = FilterCollection(filters, request, response) q = models.accepted_quotes() collection.add_to_query(q) q.order('-creation_date') if json: out = quotejson.json(q) else: out = render_template( 'cppbash/home.html', quotes = q, filter_collection = collection) response.response = [out] return response