def post(self): self._require_registration() event_key = self.request.get("event_key") if not event_key: self.response.out.write("No event key found") return event_future = Event.get_by_id_async(event_key) event = event_future.get_result() if not event: self.response.out.write("Invalid event key {}".format(event_key)) return match_futures = Match.query(Match.event == event.key).fetch_async(keys_only=True) valid_match_keys = [match.id() for match in match_futures.get_result()] num_videos = int(self.request.get("num_videos", 0)) suggestions_added = 0 for i in range(0, num_videos): yt_id = self.request.get("video_id_{}".format(i)) match_partial = self.request.get("match_partial_{}".format(i)) if not yt_id or not match_partial: continue match_key = "{}_{}".format(event_key, match_partial) if match_key not in valid_match_keys: continue status = SuggestionCreator.createMatchVideoYouTubeSuggestion(self.user_bundle.account.key, yt_id, match_key) if status == 'success': suggestions_added += 1 self.redirect('/suggest/event/video?event_key={}&num_added={}'.format(event_key, suggestions_added))
def get(self): self._require_registration() if not self.request.get("event_key"): self.redirect("/", abort=True) event_future = Event.get_by_id_async(self.request.get("event_key")) event = event_future.get_result() if not event: self.abort(404) medias_future = EventMediasQuery(event.key_name).fetch_async() medias = medias_future.get_result() medias_by_slugname = MediaHelper.group_by_slugname(medias) self.template_values.update({ "status": self.request.get("status"), "medias_by_slugname": medias_by_slugname, "event": event, }) self.response.out.write( jinja2_engine.render('suggestions/suggest_event_media.html', self.template_values))
def get(self): self._require_login("/suggest/match/video?match=%s" % self.request.get("match_key")) if not self.request.get("match_key"): self.redirect("/", abort=True) match_future = Match.get_by_id_async(self.request.get("match_key")) event_future = Event.get_by_id_async( self.request.get("match_key").split("_")[0]) match = match_future.get_result() event = event_future.get_result() if not match or not event: self.abort(404) self.template_values.update({ "status": self.request.get("status"), "event": event, "match": match, }) self.response.out.write( jinja2_engine.render('suggest_match_video.html', self.template_values))
def _render(self, match_key): try: match_future = Match.get_by_id_async(match_key) event_future = Event.get_by_id_async(match_key.split("_")[0]) match = match_future.get_result() event = event_future.get_result() except Exception, e: return self.redirect("/error/404")
def _render(self, match_key): try: match_future = Match.get_by_id_async(match_key) event_future = Event.get_by_id_async(match_key.split("_")[0]) match = match_future.get_result() event = event_future.get_result() except Exception, e: self.abort(404)
def validate_request(cls, handler): kwargs = handler.request.route_kwargs error_dict = {'Errors': []} valid = True team_future = None event_future = None match_future = None # Check key formats if 'team_key' in kwargs: team_key = kwargs['team_key'] results = cls.team_id_validator(team_key) if results: error_dict['Errors'].append(results) valid = False else: team_future = Team.get_by_id_async(team_key) if 'event_key' in kwargs: event_key = kwargs['event_key'] results = cls.event_id_validator(event_key) if results: error_dict['Errors'].append(results) valid = False else: event_future = Event.get_by_id_async(event_key) if 'match_key' in kwargs: match_key = kwargs['match_key'] results = cls.match_id_validator(match_key) if results: error_dict['Errors'].append(results) valid = False else: match_future = Match.get_by_id_async(match_key) if 'district_key' in kwargs: district_key = kwargs['district_key'] results = cls.district_id_validator(district_key) if results: error_dict['Errors'].append(results) valid = False if 'year' in kwargs: year = int(kwargs['year']) if year > tba_config.MAX_YEAR or year < 1992: error_dict['Errors'].append({'year': 'Invalid year: {}. Must be between 1992 and {} inclusive.'.format(year, tba_config.MAX_YEAR)}) valid = False # Check if keys exist if team_future and team_future.get_result() is None: error_dict['Errors'].append({'team_id': 'team id {} does not exist'.format(team_key)}) valid = False if event_future and event_future.get_result() is None: error_dict['Errors'].append({'event_id': 'event id {} does not exist'.format(event_key)}) valid = False if match_future and match_future.get_result() is None: error_dict['Errors'].append({'match_id': 'match id {} does not exist'.format(match_key)}) valid = False if not valid: return error_dict
def get(self): suggestions = Suggestion.query().filter( Suggestion.review_state == Suggestion.REVIEW_PENDING).filter( Suggestion.target_model == "match").fetch(limit=50) # Roughly sort by event and match for easier review suggestions = sorted(suggestions, key=lambda s: s.target_key) event_futures = [Event.get_by_id_async(suggestion.target_key.split("_")[0]) for suggestion in suggestions] events = [event_future.get_result() for event_future in event_futures] self.template_values.update({ "suggestions_and_events": zip(suggestions, events), }) self.response.out.write(jinja2_engine.render('suggestions/suggest_match_video_review_list.html', self.template_values))
def get(self, event_key): # Fetch for later event_future = Event.get_by_id_async(event_key) matches_future = match_query.EventMatchesQuery(event_key).fetch_async() # Rebuild event teams taskqueue.add( url='/tasks/math/do/eventteam_update/' + event_key, method='GET') # Create Winner/Finalist awards for offseason events awards = [] event = event_future.get_result() if event.event_type_enum in {EventType.OFFSEASON, EventType.FOC}: matches = MatchHelper.organizeMatches(matches_future.get_result()) bracket = MatchHelper.generateBracket(matches, event, event.alliance_selections) if 'f' in bracket: winning_alliance = '{}_alliance'.format(bracket['f'][1]['winning_alliance']) if winning_alliance == 'red_alliance': losing_alliance = 'blue_alliance' else: losing_alliance = 'red_alliance' awards.append(Award( id=Award.render_key_name(event.key_name, AwardType.WINNER), name_str="Winner", award_type_enum=AwardType.WINNER, year=event.year, event=event.key, event_type_enum=event.event_type_enum, team_list=[ndb.Key(Team, 'frc{}'.format(team)) for team in bracket['f'][1][winning_alliance] if team.isdigit()], recipient_json_list=[json.dumps({'team_number': team, 'awardee': None}) for team in bracket['f'][1][winning_alliance]], )) awards.append(Award( id=Award.render_key_name(event.key_name, AwardType.FINALIST), name_str="Finalist", award_type_enum=AwardType.FINALIST, year=event.year, event=event.key, event_type_enum=event.event_type_enum, team_list=[ndb.Key(Team, 'frc{}'.format(team)) for team in bracket['f'][1][losing_alliance] if team.isdigit()], recipient_json_list=[json.dumps({'team_number': team, 'awardee': None}) for team in bracket['f'][1][losing_alliance]], )) AwardManipulator.createOrUpdate(awards) self.response.out.write("Finished post-event tasks for {}. Created awards: {}".format(event_key, awards))
def get(self): self._require_registration() if not self.request.get("event_key"): self.redirect("/", abort=True) event_future = Event.get_by_id_async(self.request.get("event_key")) event = event_future.get_result() if not event: self.abort(404) self.template_values.update({ "event": event, "num_added": self.request.get("num_added") }) self.response.out.write(jinja2_engine.render('suggest_match_video_playlist.html', self.template_values))
def get(self): self._require_registration() if not self.request.get("event_key"): self.redirect("/", abort=True) event_future = Event.get_by_id_async(self.request.get("event_key")) event = event_future.get_result() if not event: self.abort(404) self.template_values.update({ "event": event, "num_added": self.request.get("num_added") }) self.response.out.write(jinja2_engine.render('suggestions/suggest_match_video_playlist.html', self.template_values))
def get(self): self._require_login("/suggest/match/video?match=%s" % self.request.get("match_key")) if not self.request.get("match_key"): self.redirect("/", abort=True) match_future = Match.get_by_id_async(self.request.get("match_key")) event_future = Event.get_by_id_async(self.request.get("match_key").split("_")[0]) match = match_future.get_result() event = event_future.get_result() self.template_values.update({ "success": self.request.get("success"), "event": event, "match": match, }) path = os.path.join(os.path.dirname(__file__), '../../templates/suggest_match_video.html') self.response.out.write(template.render(path, self.template_values))
def get(self): self._require_registration() if not self.request.get("match_key"): self.redirect("/", abort=True) match_future = Match.get_by_id_async(self.request.get("match_key")) event_future = Event.get_by_id_async(self.request.get("match_key").split("_")[0]) match = match_future.get_result() event = event_future.get_result() if not match or not event: self.abort(404) self.template_values.update({ "status": self.request.get("status"), "event": event, "match": match, }) self.response.out.write(jinja2_engine.render('suggestions/suggest_match_video.html', self.template_values))
def get(self): self._require_login("/suggest/match/video?match=%s" % self.request.get("match_key")) if not self.request.get("match_key"): self.redirect("/", abort=True) match_future = Match.get_by_id_async(self.request.get("match_key")) event_future = Event.get_by_id_async( self.request.get("match_key").split("_")[0]) match = match_future.get_result() event = event_future.get_result() self.template_values.update({ "success": self.request.get("success"), "event": event, "match": match, }) path = os.path.join(os.path.dirname(__file__), '../../templates/suggest_match_video.html') self.response.out.write(template.render(path, self.template_values))
def get(self): self._require_registration() if not self.request.get("event_key"): self.redirect("/", abort=True) event_future = Event.get_by_id_async(self.request.get("event_key")) event = event_future.get_result() if not event: self.abort(404) medias_future = EventMediasQuery(event.key_name).fetch_async() medias = medias_future.get_result() medias_by_slugname = MediaHelper.group_by_slugname(medias) self.template_values.update({ "status": self.request.get("status"), "medias_by_slugname": medias_by_slugname, "event": event, }) self.response.out.write(jinja2_engine.render('suggestions/suggest_event_media.html', self.template_values))
def get(self): suggestions = Suggestion.query().filter( Suggestion.review_state == Suggestion.REVIEW_PENDING).filter( Suggestion.target_model == "match").fetch(limit=50) # Roughly sort by event and match for easier review suggestions = sorted(suggestions, key=lambda s: s.target_key) event_futures = [ Event.get_by_id_async(suggestion.target_key.split("_")[0]) for suggestion in suggestions ] events = [event_future.get_result() for event_future in event_futures] self.template_values.update({ "suggestions_and_events": zip(suggestions, events), }) self.response.out.write( jinja2_engine.render( 'suggestions/suggest_match_video_review_list.html', self.template_values))
def _query_async(self): event_key = self._query_args[0] event = yield Event.get_by_id_async(event_key) divisions = yield ndb.get_multi_async(event.divisions) raise ndb.Return(divisions)
def _query_async(self): event_key = self._query_args[0] event = yield Event.get_by_id_async(event_key) raise ndb.Return(event)
def validate_request(cls, handler): kwargs = handler.request.route_kwargs error_dict = {'Errors': []} valid = True team_future = None event_future = None match_future = None district_future = None # Check key formats if 'team_key' in kwargs: team_key = kwargs['team_key'] results = cls.team_id_validator(team_key) if results: error_dict['Errors'].append(results) valid = False else: team_future = Team.get_by_id_async(team_key) if 'event_key' in kwargs: event_key = kwargs['event_key'] results = cls.event_id_validator(event_key) if results: error_dict['Errors'].append(results) valid = False else: event_future = Event.get_by_id_async(event_key) if 'match_key' in kwargs: match_key = kwargs['match_key'] results = cls.match_id_validator(match_key) if results: error_dict['Errors'].append(results) valid = False else: match_future = Match.get_by_id_async(match_key) if 'district_key' in kwargs: district_key = kwargs['district_key'] results = cls.district_id_validator(district_key) if results: error_dict['Errors'].append(results) valid = False else: district_future = District.get_by_id_async(district_key) if 'year' in kwargs: year = int(kwargs['year']) if year > tba_config.MAX_YEAR or year < 1992: error_dict['Errors'].append({ 'year': 'Invalid year: {}. Must be between 1992 and {} inclusive.'. format(year, tba_config.MAX_YEAR) }) valid = False # Check if keys exist if team_future and team_future.get_result() is None: error_dict['Errors'].append( {'team_id': 'team id {} does not exist'.format(team_key)}) valid = False if event_future and event_future.get_result() is None: error_dict['Errors'].append( {'event_id': 'event id {} does not exist'.format(event_key)}) valid = False if match_future and match_future.get_result() is None: error_dict['Errors'].append( {'match_id': 'match id {} does not exist'.format(match_key)}) valid = False if district_future and district_future.get_result() is None: error_dict['Errors'].append({ 'district_id': 'district id {} does not exist'.format(district_key) }) valid = False if not valid: return error_dict