예제 #1
0
    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))     
예제 #2
0
    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))