def search(self, term): self.response.headers['Content-Type'] = 'application/json' dreams = Dreams.search_by_name(term) response = [] for dream in dreams: dream_json = ndb_json.loads(ndb_json.dumps(dream)) response.append(self.append_dreamer_on_response(dream_json, dream.dreamer)) self.response.out.write(ndb_json.dumps(response))
def append_dreamer_on_response(self, response, dreamer_id): dreamer = Dreamers.find(dreamer_id) response['dreamer'] = ndb_json.loads(ndb_json.dumps(dreamer)) del response['dreamer']['password'] return response
def get(self, dream_id): self.response.headers['Content-Type'] = 'application/json' dream = Dreams.find(int(dream_id)) response = ndb_json.loads(ndb_json.dumps(dream)) response = self.append_dreamer_on_response(response, dream.dreamer) self.response.out.write(ndb_json.dumps(response))
def random(self): self.response.headers['Content-Type'] = 'application/json' random_dream = Dreams.random() dream = ndb_json.loads(ndb_json.dumps(random_dream)) response = self.append_dreamer_on_response(dream, random_dream.dreamer) self.response.out.write(ndb_json.dumps(response))