def put(self, **kwargs): game_id = kwargs.get("game_id") results = ndb.Key(Results, game_id).get() if results is not None: self.abort(409) req_json = json.loads(self.request.body) results_json = json.dumps(req_json['results']) if 'is_public' in req_json: is_public = req_json['is_public'] else: is_public = False key = ndb.Key(urlsafe=game_id) if key.kind() == 'PreGame': pregame = key.get() settings = json.loads(pregame.game_json)['meta'] if 'is_public' in settings: is_public = is_public or settings['is_public'] devices = pregame.device_ids else: devices = [self.device_id] players_ids = [get_device_and_user(device)[1] for device in devices] results = Results(id=game_id) results.results_json = results_json results.players_ids = players_ids results.timestamp = make_timestamp() results.is_public = is_public results.put() self.response.set_status(201)
def get(self, **kwargs): timestamp = kwargs["timestamp"] results = Results.query(Results.players_ids == self.user_key, Results.timestamp > int(timestamp)) response = {'results': [result.results_json for result in results], 'timestamp': make_timestamp()} self.response.write(json.dumps(response))
def get(self, **kwargs): timestamp = kwargs["timestamp"] results = Results.query(Results.players_ids == self.user_key, Results.timestamp > int(timestamp)) response = { 'results': [result.results_json for result in results], 'timestamp': make_timestamp() } self.response.write(json.dumps(response))