def get(self, year): year_event_keys = Event.query(Event.year == int(year)).fetch(1000, keys_only=True) final_match_keys = [] for event_key in year_event_keys: final_match_keys.extend(Match.query(Match.event == event_key, Match.comp_level == 'f').fetch(100, keys_only=True)) match_keys_to_repair = [] for match_key in final_match_keys: key_name = match_key.id() if '_f0m' in key_name: match_keys_to_repair.append(match_key) deleted_keys = [] matches_to_repair = ndb.get_multi(match_keys_to_repair) for match in matches_to_repair: deleted_keys.append(match.key) event = ndb.get_multi([match.event])[0] match.set_number = 1 match.key = ndb.Key(Match, Match.renderKeyName( event.key.id(), match.comp_level, match.set_number, match.match_number)) MatchManipulator.createOrUpdate(matches_to_repair) MatchManipulator.delete_keys(deleted_keys) template_values = {'deleted_keys': deleted_keys, 'new_matches': matches_to_repair} path = os.path.join(os.path.dirname(__file__), '../templates/math/final_matches_repair_do.html') self.response.out.write(template.render(path, template_values))
def get(self, year): year_event_keys = Event.query(Event.year == int(year)).fetch(1000, keys_only=True) final_match_keys = [] for event_key in year_event_keys: final_match_keys.extend(Match.query(Match.event == event_key, Match.comp_level == 'f').fetch(100, keys_only=True)) match_keys_to_repair = [] for match_key in final_match_keys: key_name = match_key.id() if '_f0m' in key_name: match_keys_to_repair.append(match_key) deleted_keys = [] matches_to_repair = ndb.get_multi(match_keys_to_repair) for match in matches_to_repair: deleted_keys.append(match.key) event = ndb.get_multi([match.event])[0] match.set_number = 1 match.key = ndb.Key(Match, Match.renderKeyName( event.key.id(), match.comp_level, match.set_number, match.match_number)) MatchManipulator.createOrUpdate(matches_to_repair) MatchManipulator.delete_keys(deleted_keys) template_values = {'deleted_keys': deleted_keys, 'new_matches': matches_to_repair} path = os.path.join(os.path.dirname(__file__), '../templates/math/final_matches_repair_do.html') self.response.out.write(template.render(path, template_values))
def _process_request(self, request, event_key): if request.body != event_key: self._errors = json.dumps({"Error": "To delete all matches for this event, the body of the request must be the event key."}) self.abort(400) keys_to_delete = Match.query(Match.event == ndb.Key(Event, event_key)).fetch(keys_only=True) MatchManipulator.delete_keys(keys_to_delete) self.response.out.write(json.dumps({'Success': "All matches for {} deleted".format(event_key)}))
def _process_request(self, request, event_key): if request.body != event_key: self._errors = json.dumps({"Error": "To delete all matches for this event, the body of the request must be the event key."}) self.abort(400) keys_to_delete = Match.query(Match.event == ndb.Key(Event, event_key)).fetch(keys_only=True) MatchManipulator.delete_keys(keys_to_delete) self.response.out.write(json.dumps({'Success': "All matches for {} deleted".format(event_key)}))
def _process_request(self, request, event_key): keys_to_delete = set() try: match_keys = json.loads(request.body) except Exception: self._errors = json.dumps({"Error": "'keys_to_delete' could not be parsed"}) self.abort(400) for match_key in match_keys: keys_to_delete.add(ndb.Key(Match, '{}_{}'.format(event_key, match_key))) MatchManipulator.delete_keys(keys_to_delete) self.response.out.write(json.dumps({'keys_deleted': [key.id().split('_')[1] for key in keys_to_delete]}))
def _process_request(self, request, event_key): keys_to_delete = set() try: match_keys = json.loads(request.body) except Exception: self._errors = json.dumps({"Error": "'keys_to_delete' could not be parsed"}) self.abort(400) for match_key in match_keys: keys_to_delete.add(ndb.Key(Match, '{}_{}'.format(event_key, match_key))) MatchManipulator.delete_keys(keys_to_delete) ret = json.dumps({"keys_deleted": [key.id().split('_')[1] for key in keys_to_delete]}) self.response.out.write(ret)