def get(self): self.response.headers['Access-Control-Allow-Origin'] = "*" tags = Tag.query().order(-Tag.count, -Tag.added).fetch(20) reply = [] for tag in tags: reply.append(Tag.to_json_object(tag)) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps(reply))
def autocomplete(self, hint): self.response.headers['Access-Control-Allow-Origin'] = "*" query = Tag.query( ndb.AND( Tag.key >= ndb.Key(Tag, hint), Tag.key <= ndb.Key(Tag, hint + u'\ufffd') ) ) query.order(-Tag.count, -Tag.added) tags = query.fetch(20) reply = [] for tag in tags: print tag.key.string_id() reply.append(Tag.to_json_object(tag)) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps(reply))