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: self.abort(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: return self.redirect("/error/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 accept_suggestions(self, suggestions): if (len(suggestions) < 1): return None matches = map(lambda match_future: match_future.get_result(), [Match.get_by_id_async(suggestion.target_key) for suggestion in suggestions]) pairs = zip(matches, suggestions) for match, suggestion in pairs: self._accept_suggestion(match, suggestion) matches, suggestions = zip(*pairs) matches = MatchManipulator.createOrUpdate(list(matches)) return matches
def accept_suggestions(self, suggestions): if (len(suggestions) < 1): return None matches = map(lambda match_future: match_future.get_result(), [ Match.get_by_id_async(suggestion.target_key) for suggestion in suggestions ]) pairs = zip(matches, suggestions) for match, suggestion in pairs: self._accept_suggestion(match, suggestion) matches, suggestions = zip(*pairs) matches = MatchManipulator.createOrUpdate(list(matches)) return matches
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 post(self): self._require_login() match_key = self.request.get("match_key") match_future = Match.get_by_id_async(self.request.get("match_key")) youtube_url = self.request.get("youtube_url") youtube_id = None regex1 = re.match(r".*youtu\.be\/(.*)", youtube_url) if regex1 is not None: youtube_id = regex1.group(1) else: regex2 = re.match(r".*v=([a-zA-Z0-9_-]*)", youtube_url) if regex2 is not None: youtube_id = regex2.group(1) if youtube_id is not None: if youtube_id not in match_future.get_result().youtube_videos: year = match_key[:4] suggestion_id = Suggestion.render_media_key_name(year, 'match', match_key, 'youtube', youtube_id) suggestion = Suggestion.get_by_id(suggestion_id) if not suggestion or suggestion.review_state != Suggestion.REVIEW_PENDING: suggestion = Suggestion( id=suggestion_id, author=self.user_bundle.account.key, target_key=match_key, target_model="match", ) suggestion.contents = {"youtube_videos": [youtube_id]} suggestion.put() status = 'success' else: status = 'suggestion_exists' else: status = 'video_exists' else: status = 'bad_url' self.redirect('/suggest/match/video?match_key={}&status={}'.format(match_key, status))
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 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
def _query_async(self): match_key = self._query_args[0] match = yield Match.get_by_id_async(match_key) raise ndb.Return(match)