def post(self): if self.request.get("verdict") == "accept": webcast = dict() webcast["type"] = self.request.get("webcast_type") webcast["channel"] = self.request.get("webcast_channel") if self.request.get("webcast_file"): webcast["file"] = self.request.get("webcast_file") event = Event.get_by_id(self.request.get("event_key")) suggestion = Suggestion.get_by_id( int(self.request.get("suggestion_key"))) EventWebcastAdder.add_webcast(event, webcast) MemcacheWebcastFlusher.flush() suggestion.review_state = Suggestion.REVIEW_ACCEPTED suggestion.reviewer = self.user_bundle.account.key suggestion.reviewer_at = datetime.datetime.now() suggestion.put() self.redirect( "/suggest/event/webcast/review?success=accept&event_key=%s" % event.key.id()) return elif self.request.get("verdict") == "reject": suggestion = Suggestion.get_by_id( int(self.request.get("suggestion_key"))) suggestion.review_state = Suggestion.REVIEW_REJECTED suggestion.reviewer = self.user_bundle.account.key suggestion.reviewer_at = datetime.datetime.now() suggestion.put() self.redirect("/suggest/event/webcast/review?success=reject") return elif self.request.get("verdict") == "reject_all": suggestion_keys = self.request.get("suggestion_keys").split(",") suggestions = [ Suggestion.get_by_id(int(suggestion_key)) for suggestion_key in suggestion_keys ] for suggestion in suggestions: event_key = suggestion.target_key suggestion.review_state = Suggestion.REVIEW_REJECTED suggestion.reviewer = self.user_bundle.account.key suggestion.reviewer_at = datetime.datetime.now() suggestion.put() self.redirect( "/suggest/event/webcast/review?success=reject_all&event_key=%s" % event_key) return self.redirect("/suggest/event/webcast/review")
def create_target_model(self, suggestion): webcast = dict() webcast["type"] = self.request.get("webcast_type") webcast["channel"] = self.request.get("webcast_channel") if self.request.get("webcast_file"): webcast["file"] = self.request.get("webcast_file") event = Event.get_by_id(self.request.get("event_key")) EventWebcastAdder.add_webcast(event, webcast) MemcacheWebcastFlusher.flush()
def post(self): self._require_admin() if self.request.get("verdict") == "accept": webcast = dict() webcast["type"] = self.request.get("webcast_type") webcast["channel"] = self.request.get("webcast_channel") if self.request.get("webcast_file"): webcast["file"] = self.request.get("webcast_file") event = Event.get_by_id(self.request.get("event_key")) suggestion = Suggestion.get_by_id(int(self.request.get("suggestion_key"))) EventWebcastAdder.add_webcast(event, webcast) MemcacheWebcastFlusher.flush() suggestion.review_state = Suggestion.REVIEW_ACCEPTED suggestion.reviewer = self.user_bundle.account.key suggestion.reviewer_at = datetime.datetime.now() suggestion.put() self.redirect("/admin/suggestions/event/webcast/review?success=accept&event_key=%s" % event.key.id()) return elif self.request.get("verdict") == "reject": suggestion = Suggestion.get_by_id(int(self.request.get("suggestion_key"))) suggestion.review_state = Suggestion.REVIEW_REJECTED suggestion.reviewer = self.user_bundle.account.key suggestion.reviewer_at = datetime.datetime.now() suggestion.put() self.redirect("/admin/suggestions/event/webcast/review?success=reject") return elif self.request.get("verdict") == "reject_all": suggestion_keys = self.request.get("suggestion_keys").split(",") suggestions = [Suggestion.get_by_id(int(suggestion_key)) for suggestion_key in suggestion_keys] for suggestion in suggestions: event_key = suggestion.target_key suggestion.review_state = Suggestion.REVIEW_REJECTED suggestion.reviewer = self.user_bundle.account.key suggestion.reviewer_at = datetime.datetime.now() suggestion.put() self.redirect("/admin/suggestions/event/webcast/review?success=reject_all&event_key=%s" % event_key) return self.redirect("/admin/suggestions/event/webcast/review")
def post(self, event_key_id): self._require_admin() webcast = dict() webcast["type"] = self.request.get("webcast_type") webcast["channel"] = self.request.get("webcast_channel") if self.request.get("webcast_file"): webcast["file"] = self.request.get("webcast_file") event = Event.get_by_id(event_key_id) EventWebcastAdder.add_webcast(event, webcast) self.redirect("/admin/event/" + event.key_name)
def _process_request(self, request, event_key): try: event_info = json.loads(request.body) except Exception: self._errors = json.dumps({"Error": "Invalid json. Check input."}) self.abort(400) if not isinstance(event_info, dict) or not event_info: self._errors = json.dumps({"Error": "Invalid json. Check input."}) self.abort(400) event = Event.get_by_id(event_key) if not event: self._errors = json.dumps( {"Error": "Event {} not found".format(event_key)}) self.abort(404) do_team_remap = False for field, value in event_info.iteritems(): if field not in self.ALLOWED_EVENT_PARAMS: continue if field == "webcasts": # Do special processing here because webcasts are janky if not isinstance(value, list): self._errors = json.dumps( {"Error": "Invalid json. Check input"}) self.abort(400) return webcast_list = [] for webcast in value: if not isinstance(webcast, dict): self._errors = json.dumps( {"Error": "Invalid json. Check input"}) self.abort(400) return if 'url' in webcast: webcast_list.append( WebcastParser.webcast_dict_from_url( webcast['url'])) elif 'type' in webcast and 'channel' in webcast: webcast_list.append(webcast) webcast_list = [w for w in webcast_list if w is not None] EventWebcastAdder.add_webcast( event, webcast_list, False, # Don't createOrUpdate yet ) elif field == "remap_teams": # Validate remap_teams if not isinstance(value, dict): raise ParserInputException( "Invalid reamap_teams. Check input") for temp_team, remapped_team in value.items(): temp_match = re.match(r'frc\d+', str(temp_team)) remapped_match = re.match(r'frc\d+[B-Z]?', str(remapped_team)) if not temp_match or ( temp_match and (temp_match.group(0) != str(temp_team))): raise ParserInputException( "Bad team: '{}'. Must follow format 'frcXXX'.". format(temp_team)) if not remapped_match or ( remapped_match and (remapped_match.group(0) != str(remapped_team))): raise ParserInputException( "Bad team: '{}'. Must follow format 'frcXXX' or 'frcXXX[B-Z]'." .format(remapped_team)) do_team_remap = True setattr(event, field, value) else: try: if field == "first_event_code": event.official = value is not None field = "first_code" # Internal property is different setattr(event, field, value) except Exception, e: self._errors({ "Error": "Unable to set event field", "Message": str(e) }) self.abort(400)
def _process_request(self, request, event_key): try: event_info = json.loads(request.body) except Exception: self._errors = json.dumps({"Error": "Invalid json. Check input."}) self.abort(400) if not isinstance(event_info, dict) or not event_info: self._errors = json.dumps({"Error": "Invalid json. Check input."}) self.abort(400) do_team_remap = False for field, value in event_info.iteritems(): if field not in self.ALLOWED_EVENT_PARAMS: continue if field == "webcasts": # Do special processing here because webcasts are janky if not isinstance(value, list): self._errors = json.dumps( {"Error": "Invalid json. Check input"} ) self.abort(400) return webcast_list = [] for webcast in value: if not isinstance(webcast, dict): self._errors = json.dumps( {"Error": "Invalid json. Check input"} ) self.abort(400) return if 'url' in webcast: webcast_list.append( WebcastParser.webcast_dict_from_url(webcast['url']) ) elif 'type' in webcast and 'channel' in webcast: webcast_list.append(webcast) webcast_list = [w for w in webcast_list if w is not None] EventWebcastAdder.add_webcast( self.event, webcast_list, False, # Don't createOrUpdate yet ) elif field == "remap_teams": # Validate remap_teams if not isinstance(value, dict): raise ParserInputException("Invalid reamap_teams. Check input") for temp_team, remapped_team in value.items(): temp_match = re.match(r'frc\d+', str(temp_team)) remapped_match = re.match(r'frc\d+[B-Z]?', str(remapped_team)) if not temp_match or (temp_match and (temp_match.group(0) != str(temp_team))): raise ParserInputException("Bad team: '{}'. Must follow format 'frcXXX'.".format(temp_team)) if not remapped_match or (remapped_match and (remapped_match.group(0) != str(remapped_team))): raise ParserInputException("Bad team: '{}'. Must follow format 'frcXXX' or 'frcXXX[B-Z]'.".format(remapped_team)) do_team_remap = True setattr(self.event, field, value) else: try: if field == "first_event_code": self.event.official = value is not None field = "first_code" # Internal property is different setattr(self.event, field, value) except Exception, e: self._errors({ "Error": "Unable to set event field", "Message": str(e) }) self.abort(400)