本文整理汇总了Python中models.event.Event.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Event.get_by_id方法的具体用法?Python Event.get_by_id怎么用?Python Event.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.event.Event
的用法示例。
在下文中一共展示了Event.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_target_model
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def create_target_model(self, suggestion):
event_id = self.request.get("event_short", None)
event_key = str(self.request.get("year")) + str.lower(str(self.request.get("event_short")))
if not event_id:
# Need to supply a key :(
return 'missing_key', None
if not Event.validate_key_name(event_key):
# Bad event key generated
return 'bad_key', None
start_date = None
if self.request.get("start_date"):
start_date = datetime.strptime(self.request.get("start_date"), "%Y-%m-%d")
end_date = None
if self.request.get("end_date"):
end_date = datetime.strptime(self.request.get("end_date"), "%Y-%m-%d")
existing_event = Event.get_by_id(event_key)
if existing_event:
return 'duplicate_key', None
first_code = self.request.get("first_code", '')
event = Event(
id=event_key,
end_date=end_date,
event_short=self.request.get("event_short"),
event_type_enum=EventType.OFFSEASON,
district_key=None,
venue=self.request.get("venue"),
venue_address=self.request.get("venue_address"),
city=self.request.get("city"),
state_prov=self.request.get("state"),
country=self.request.get("country"),
name=self.request.get("name"),
short_name=self.request.get("short_name"),
start_date=start_date,
website=self.request.get("website"),
year=int(self.request.get("year")),
first_code=first_code,
official=(not first_code == ''),
)
EventManipulator.createOrUpdate(event)
author = suggestion.author.get()
OutgoingNotificationHelper.send_suggestion_result_email(
to=author.email,
subject="[TBA] Offseason Event Suggestion: {}".format(event.name),
email_body="""Dear {},
Thank you for suggesting an offseason event to The Blue Alliance. Your suggestion has been approved and you can find the event at https://thebluealliance.com/event/{}
If you are the event's organizer and would like to upload teams attending, match videos, or real-time match results to TBA before or during the event, you can do so using the TBA EventWizard - request auth keys here: https://www.thebluealliance.com/request/apiwrite
Thanks for helping make TBA better,
The Blue Alliance Admins
""".format(author.nickname, event_key)
)
return 'success', event_key
开发者ID:NikhilNarayana,项目名称:the-blue-alliance,代码行数:62,代码来源:suggest_offseason_event_review_controller.py
示例2: get
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def get(self, event_key):
event = Event.get_by_id(event_key)
team_ids = set()
# Add teams from Matches
for match in Match.query(Match.event == event.key).fetch(1000):
for team in match.team_key_names:
team_ids.add(team)
teams = TeamManipulator.createOrUpdate([Team(
id = team_id,
team_number = int(team_id[3:]))
for team_id in team_ids])
if teams:
event_teams = EventTeamManipulator.createOrUpdate([EventTeam(
id = event_key + "_" + team.key.id(),
event = event.key,
team = team.key,
year = event.year)
for team in teams])
else:
event_teams = None
template_values = {
'event_teams': event_teams,
}
path = os.path.join(os.path.dirname(__file__), '../templates/math/eventteam_update_do.html')
self.response.out.write(template.render(path, template_values))
示例3: post
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def post(self):
self._require_admin()
event_key = self.request.get('event_key')
matches_csv = self.request.get('matches_csv')
matches, _ = OffseasonMatchesParser.parse(matches_csv)
event = Event.get_by_id(event_key)
matches = [Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
year=event.year,
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None)
)
for match in matches]
MatchManipulator.createOrUpdate(matches)
self.redirect('/admin/event/{}'.format(event_key))
示例4: get
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def get(self):
suggestions = Suggestion.query().filter(
Suggestion.review_state == Suggestion.REVIEW_PENDING).filter(
Suggestion.target_model == "event")
suggestions_by_event_key = {}
for suggestion in suggestions:
if 'webcast_dict' in suggestion.contents:
suggestion.webcast_template = 'webcast/{}.html'.format(suggestion.contents['webcast_dict']['type'])
suggestions_by_event_key.setdefault(suggestion.target_key, []).append(suggestion)
suggestion_sets = []
for event_key, suggestions in suggestions_by_event_key.items():
suggestion_sets.append({
"event": Event.get_by_id(event_key),
"suggestions": suggestions
})
self.template_values.update({
"event_key": self.request.get("event_key"),
"success": self.request.get("success"),
"suggestion_sets": suggestion_sets
})
path = os.path.join(os.path.dirname(__file__), '../../templates/suggest_event_webcast_review_list.html')
self.response.out.write(template.render(path, self.template_values))
示例5: post
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def post(self):
self._require_admin()
event_key = self.request.get('event_key')
matches_csv = self.request.get('matches_csv')
matches = OffseasonMatchesParser.parse(matches_csv)
event = Event.get_by_id(event_key)
matches = [Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
game=Match.FRC_GAMES_BY_YEAR.get(event.year, "frc_unknown"),
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None)
)
for match in matches]
try:
FirebasePusher.updated_event(event.key_name)
except:
logging.warning("Enqueuing Firebase push failed!")
self.redirect('/admin/event/{}'.format(event_key))
示例6: post
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def post(self):
event_key = self.request.get('event_key')
awards_json = self.request.get('awards_json')
awards = json.loads(awards_json)
event = Event.get_by_id(event_key)
def _getTeamKey(award):
team = Team.get_by_id('frc' + str(award.get('team_number', None)))
if team is not None:
return team.key
else:
return None
awards = [Award(
id = Award.renderKeyName(event.key_name, award.get('name')),
name = award.get('name', None),
team = _getTeamKey(award),
awardee = award.get('awardee', None),
year = event.year,
official_name = award.get('official_name', None),
event = event.key)
for award in awards]
AwardManipulator.createOrUpdate(awards)
self.redirect('/admin/event/{}'.format(event_key))
示例7: post
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def post(self, event_key):
self._require_login()
self._require_registration()
current_user_id = self.user_bundle.account.key.id()
event = Event.get_by_id(event_key)
subscribed_matches = set(self.request.get_all('subscribed_matches'))
for match in event.matches:
if not match.has_been_played:
match_key = match.key.id()
if match.key.id() in subscribed_matches:
sub = Subscription(
parent=ndb.Key(Account, current_user_id),
user_id=current_user_id,
model_type=ModelType.MATCH,
model_key=match_key,
notification_types=[NotificationType.UPCOMING_MATCH]
)
MyTBAHelper.add_subscription(sub)
else:
MyTBAHelper.remove_subscription(current_user_id, match_key, ModelType.MATCH)
self.redirect('/account/mytba?status=match_updated#my-matches'.format(event_key))
示例8: get
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def get(self, event_key):
df = DatafeedUsfirst()
event = Event.get_by_id(event_key)
new_matches = MatchManipulator.createOrUpdate(df.getMatches(event))
if new_matches:
for match in new_matches:
if hasattr(match, 'dirty') and match.dirty:
# Enqueue push notification
try:
FirebasePusher.updated_event(event.key_name)
except:
logging.warning("Enqueuing Firebase push failed!")
# Enqueue task to calculate matchstats
taskqueue.add(
url='/tasks/math/do/event_matchstats/' + event.key_name,
method='GET')
break
template_values = {
'matches': new_matches,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_matches_get.html')
self.response.out.write(template.render(path, template_values))
示例9: post
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def post(self, event_key_id):
self._require_admin()
event = Event.get_by_id(event_key_id)
if not event:
self.abort(404)
place_id = self.request.get('place_id')
if not place_id:
self.abort(400)
# Construct a mostly empty input struct that'll get filled in
location_input = {
'place_id': place_id,
'geometry': {
'location': {
'lat': '',
'lng': '',
},
},
'name': '',
'types': [],
}
location_info = LocationHelper.construct_location_info_async(location_input).get_result()
event.normalized_location = LocationHelper.build_normalized_location(location_info)
EventManipulator.createOrUpdate(event)
self.redirect('/admin/event/{}'.format(event_key_id))
示例10: parse
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def parse(self, response):
matches = response['MatchScores']
event_key = '{}{}'.format(self.year, self.event_short)
event = Event.get_by_id(event_key)
match_details_by_key = {}
for match in matches:
comp_level = PlayoffType.get_comp_level(event.playoff_type, match['matchLevel'], match['matchNumber'])
set_number, match_number = PlayoffType.get_set_match_number(event.playoff_type, comp_level, match['matchNumber'])
breakdown = {
'red': {},
'blue': {},
}
if 'coopertition' in match:
breakdown['coopertition'] = match['coopertition']
if 'coopertitionPoints' in match:
breakdown['coopertition_points'] = match['coopertitionPoints']
for alliance in match['Alliances']:
color = alliance['alliance'].lower()
for key, value in alliance.items():
if key != 'alliance':
breakdown[color][key] = value
match_details_by_key[Match.renderKeyName(
'{}{}'.format(self.year, self.event_short),
comp_level,
set_number,
match_number)] = breakdown
return match_details_by_key
示例11: update
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def update(self, event_key):
"""
Updates EventTeams for an event.
Returns a tuple of (teams, event_teams, event_team_keys_to_delete)
An EventTeam is valid iff the team:
a) played a match at the event,
b) the team received an award at the event,
c) or the event has not yet occurred.
"""
event = Event.get_by_id(event_key)
# Add teams from Matches and Awards
team_ids = set()
match_key_futures = Match.query(
Match.event == event.key).fetch_async(1000, keys_only=True)
award_key_futures = Award.query(
Award.event == event.key).fetch_async(1000, keys_only=True)
match_futures = ndb.get_multi_async(match_key_futures.get_result())
award_futures = ndb.get_multi_async(award_key_futures.get_result())
for match_future in match_futures:
match = match_future.get_result()
for team in match.team_key_names:
team_ids.add(team)
for award_future in award_futures:
award = award_future.get_result()
for team_key in award.team_list:
team_ids.add(team_key.id())
# Create or update EventTeams
teams = [Team(id=team_id,
team_number=int(team_id[3:]))
for team_id in team_ids]
if teams:
event_teams = [EventTeam(id=event_key + "_" + team.key.id(),
event=event.key,
team=team.key,
year=event.year)
for team in teams]
else:
event_teams = None
# Delete EventTeams for teams who did not participate in the event
# Only runs if event is over
existing_event_teams_keys = EventTeam.query(
EventTeam.event == event.key).fetch(1000, keys_only=True)
existing_event_teams = ndb.get_multi(existing_event_teams_keys)
existing_team_ids = set()
for et in existing_event_teams:
existing_team_ids.add(et.team.id())
et_keys_to_delete = set()
if event.end_date is not None and event.end_date < datetime.datetime.now():
for team_id in existing_team_ids.difference(team_ids):
et_key_name = "{}_{}".format(event.key_name, team_id)
et_keys_to_delete.add(ndb.Key(EventTeam, et_key_name))
ndb.delete_multi(et_keys_to_delete)
return teams, event_teams, et_keys_to_delete
示例12: _render
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def _render(self, event_key):
event = Event.get_by_id(event_key)
if not event:
self.abort(404)
return
medias_future = media_query.EventTeamsPreferredMediasQuery(event_key).fetch_async()
next_match = MatchHelper.upcomingMatches(event.matches, num=1)
next_match = next_match[0] if next_match else None
team_and_medias = []
if next_match:
# Organize medias by team
teams = ndb.get_multi([ndb.Key(Team, team_key) for team_key in next_match.alliances['red']['teams'] + next_match.alliances['blue']['teams']])
image_medias = MediaHelper.get_images([media for media in medias_future.get_result()])
team_medias = defaultdict(list)
for image_media in image_medias:
for reference in image_media.references:
team_medias[reference].append(image_media)
stations = ['Red 1', 'Red 2', 'Red 3', 'Blue 1', 'Blue 2', 'Blue 3']
for i, team in enumerate(teams):
team_and_medias.append((team, stations[i], team_medias.get(team.key, [])))
self.template_values.update({
'event': event,
'next_match': next_match,
'teams_and_media': team_and_medias,
})
return jinja2_engine.render('nextmatch.html', self.template_values)
示例13: getMatches
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def getMatches(self, event_key):
year = int(event_key[:4])
event_short = event_key[4:]
event = Event.get_by_id(event_key)
hs_parser = FMSAPIHybridScheduleParser(year, event_short)
detail_parser = FMSAPIMatchDetailsParser(year, event_short)
qual_matches_future = self._parse_async(self.FMS_API_HYBRID_SCHEDULE_QUAL_URL_PATTERN % (year, self._get_event_short(event_short, event)), hs_parser)
playoff_matches_future = self._parse_async(self.FMS_API_HYBRID_SCHEDULE_PLAYOFF_URL_PATTERN % (year, self._get_event_short(event_short, event)), hs_parser)
qual_details_future = self._parse_async(self.FMS_API_MATCH_DETAILS_QUAL_URL_PATTERN % (year, self._get_event_short(event_short, event)), detail_parser)
playoff_details_future = self._parse_async(self.FMS_API_MATCH_DETAILS_PLAYOFF_URL_PATTERN % (year, self._get_event_short(event_short, event)), detail_parser)
matches_by_key = {}
qual_matches = qual_matches_future.get_result()
if qual_matches is not None:
for match in qual_matches[0]:
matches_by_key[match.key.id()] = match
playoff_matches = playoff_matches_future.get_result()
if playoff_matches is not None:
for match in playoff_matches[0]:
matches_by_key[match.key.id()] = match
qual_details = qual_details_future.get_result()
qual_details_items = qual_details.items() if qual_details is not None else []
playoff_details = playoff_details_future.get_result()
playoff_details_items = playoff_details.items() if playoff_details is not None else []
for match_key, match_details in qual_details_items + playoff_details_items:
match_key = playoff_matches[1].get(match_key, match_key)
if match_key in matches_by_key:
matches_by_key[match_key].score_breakdown_json = json.dumps(match_details)
return filter(
lambda m: not FMSAPIHybridScheduleParser.is_blank_match(m),
matches_by_key.values())
示例14: getEventAlliances
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def getEventAlliances(self, event_key):
year = int(event_key[:4])
event_short = event_key[4:]
event = Event.get_by_id(event_key)
alliances = self._parse(self.FMS_API_EVENT_ALLIANCES_URL_PATTERN % (year, self._get_event_short(event_short, event)), FMSAPIEventAlliancesParser())
return alliances
示例15: _process_request
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import get_by_id [as 别名]
def _process_request(self, request, event_key):
alliance_selections = JSONAllianceSelectionsParser.parse(request.body)
event = Event.get_by_id(event_key)
event.alliance_selections_json = json.dumps(alliance_selections)
event.dirty = True # TODO: hacky
EventManipulator.createOrUpdate(event)